예제 #1
0
파일: actions.py 프로젝트: kissthink/rdopkg
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()