Example #1
0
def diff(version, new_version, bump_only=False, no_diff=False, version_tag_style=None):
    if bump_only or no_diff:
        return
    vtag_from = guess.version2tag(version, version_tag_style)
    vtag_to = guess.version2tag(new_version, version_tag_style)
    git("--no-pager", "diff", "--stat", "%s..%s" % (vtag_from, vtag_to), direct=True)
    try:
        reqdiff(vtag_from, vtag_to)
    except Exception:
        pass
    raw_input("Press <Enter> to continue after you inspected the diff. ")
Example #2
0
def show_patch_log(version, patches_branch, version_tag_style=None):
    tag = guess.version2tag(version, version_tag_style)
    patches = git.get_commits(tag, patches_branch)
    spec = specfile.Spec()
    n_excluded = spec.get_n_excluded_patches()
    print("\nPatches branch {t.bold}{pb}{t.normal} is at version {t.bold}"
          "{ver}{t.normal}".format(
          t=log.term, pb=patches_branch, ver=version))
    _print_patch_log(patches, tag, n_excluded)
Example #3
0
def update_patches(branch, local_patches_branch,
                   version=None, new_version=None, version_tag_style=None,
                   amend=False, bump_only=False):
    if bump_only:
        return
    target_version = new_version or version
    if not target_version:
        raise exception.RequiredActionArgumentNotAvailable(
            action='update_patches',
            arg='version or new_version')
    tag = guess.version2tag(target_version, version_tag_style)
    _ensure_branch(local_patches_branch)
    patches = git.get_commits(tag, local_patches_branch)
    n_patches = len(patches)
    _ensure_branch(branch)
    spec = specfile.Spec()
    spec.sanity_check()
    n_excluded = spec.get_n_excluded_patches()

    patch_fns = spec.get_patch_fns()
    for pfn in patch_fns:
        git('rm', '--ignore-unmatch', pfn)
    patch_fns = []

    if n_excluded > 0:
        patches = patches[:-n_excluded]
    log.info("\n{t.bold}{n} patches{t.normal} on top of {t.bold}{tag}{t.normal}"
             ", {t.bold}{ne}{t.normal} excluded".format(
        t=log.term, n=n_patches, tag=tag, ne=n_excluded))

    if patches:
        start_commit = patches[-1][0]
        for hsh, title in patches:
            log.info("%s  %s" % (log.term.green(hsh), title))

        rng = git.rev_range(start_commit + '~', local_patches_branch)
        o = git('format-patch', '--no-renames', '--no-signature', '-N',
                '--ignore-submodules', rng)
        patch_fns = git._parse_output(o)
        for pfn in patch_fns:
            git('add', pfn)

    spec.set_new_patches(patch_fns)
    patches_branch_ref = git('rev-parse', local_patches_branch)
    spec.set_commit_ref_macro(patches_branch_ref)
    spec.save()
    if git.is_clean():
        log.info('No new patches.')
        return
    msg = 'Updated patches from ' + local_patches_branch
    git('commit', '-a', '-m', msg)
    if amend:
        git.squash_last()
Example #4
0
def new_version_setup(patches_branch=None, local_patches=False,
                      new_version=None, version_tag_style=None):
    args = {}
    if new_version:
        # support both version and tag
        ver, _ = guess.tag2version(new_version)
        if ver != new_version:
            new_version = ver
            args['new_version'] = new_version
        new_version_tag = guess.version2tag(new_version, version_tag_style)
    else:
        ub = guess.upstream_branch()
        if not git.ref_exists('refs/remotes/%s' % ub):
            msg=("Upstream branch not found: %s\n"
                 "Can't guess latest version.\n\n"
                 "a) provide new version (git tag) yourself\n"
                 "   $ rdopkg new-version 1.2.3\n\n"
                 "b) add upstream git remote:\n"
                 "   $ git remote add -f upstream GIT_URL\n"
                 % ub)
            raise exception.CantGuess(msg=msg)
        new_version_tag = git.get_latest_tag(ub)
        new_version, _ = guess.tag2version(new_version_tag)
        args['new_version'] = new_version
        log.info("Latest version detected from %s: %s" % (ub, new_version))
    args['changes'] = ['Update to %s' % new_version]
    args['new_patches_base'] = new_version_tag
    spec = specfile.Spec()
    rpm_version = spec.get_tag('Version')
    new_rpm_version, new_milestone = specfile.version_parts(new_version)
    args['new_rpm_version'] = new_rpm_version
    if new_milestone:
        args['new_milestone'] = new_milestone
    if rpm_version != new_rpm_version:
        if new_milestone:
            args['new_release'] = '0.1'
        else:
            args['new_release'] = '1'
    if not local_patches:
        if not patches_branch or \
           not git.ref_exists('refs/remotes/' + patches_branch):
            log.warn("Patches branch '%s' not found. Running in --bump-only "
                     "mode." % patches_branch)
            args['bump_only'] = True
    return args
Example #5
0
def rebase_patches_branch(
    new_version, local_patches_branch, patches_branch=None, local_patches=False, bump_only=False, version_tag_style=None
):
    if bump_only:
        return
    git.checkout(local_patches_branch)
    new_version_tag = guess.version2tag(new_version, version_tag_style)
    git("rebase", new_version_tag, direct=True)
    if local_patches or not patches_branch:
        return
    if _is_same_commit(local_patches_branch, patches_branch):
        log.info("%s is up to date, no need for push." % patches_branch)
        return
    try:
        remote, branch = git.remote_branch_split(patches_branch)
        helpers.confirm("Push %s to %s / %s (with --force)?" % (local_patches_branch, remote, branch))
        git("push", "--force", remote, "%s:%s" % (local_patches_branch, branch))
        # push the tag
        git("push", "--force", remote, new_version_tag)
    except exception.UserAbort:
        pass
Example #6
0
def check_new_patches(
    version, local_patches_branch, local_patches=False, patches_branch=None, changes=None, version_tag_style=None
):
    if not changes:
        changes = []
    if local_patches:
        head = local_patches_branch
    else:
        if not patches_branch:
            raise exception.RequiredActionArgumentNotAvailable(action="check_new_patches", arg="patches_branch")
        head = patches_branch
    spec = specfile.Spec()
    n_patches = spec.get_n_patches() + spec.get_n_excluded_patches()
    version_tag = guess.version2tag(version, version_tag_style)
    patches = git.get_commit_subjects(version_tag, head)
    if n_patches > 0:
        patches = patches[0:-n_patches]
    if not patches:
        log.warn("No new patches detected in %s." % head)
        helpers.confirm("Do you want to continue anyway?", default_yes=False)
    changes.extend(patches)
    return {"changes": changes}