Signed-off-by: Yann Dirson <ydirson@xxxxxxxxxx> --- stgit/commands/common.py | 23 +++++++++++++++++++++++ stgit/commands/pull.py | 20 ++++---------------- stgit/commands/rebase.py | 17 +++-------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 432edce..a352d89 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -346,3 +346,26 @@ def make_patch_name(msg, unacceptable, default_name = 'patch', suffix += 1 patchname = '%s-%d' % (patchname, suffix) return patchname + +def prepare_rebase(): + # pop all patches + applied = crt_series.get_applied() + if len(applied) > 0: + print 'Popping all applied patches...', + sys.stdout.flush() + crt_series.pop_patch(applied[0]) + print 'done' + return applied + +def rebase(target): + if target == git.get_head(): + print 'Already at "%s", no need for rebasing.' % target + return + + print 'Rebasing to "%s"...' % target + git.reset(tree_id = git_id(target)) + +def post_rebase(applied, nopush, merged): + # push the patches back + if not nopush: + push_patches(applied, merged) diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py index 2d4a782..83a2725 100644 --- a/stgit/commands/pull.py +++ b/stgit/commands/pull.py @@ -61,27 +61,15 @@ def func(parser, options, args): check_conflicts() check_head_top_equal() - # pop all patches - applied = crt_series.get_applied() - if len(applied) > 0: - print 'Popping all applied patches...', - sys.stdout.flush() - crt_series.pop_patch(applied[0]) - print 'done' + applied = prepare_rebase() # pull the remote changes print 'Pulling from "%s"...' % repository git.fetch(repository) if (config.get('stgit.pull-does-rebase') == 'yes'): - fetch_head = git.fetch_head() - if fetch_head != git.get_head(): - print 'rebasing to "%s"...' % fetch_head - git.reset(tree_id = fetch_head) - print 'done' - - # push the patches back - if not options.nopush: - push_patches(applied, options.merged) + rebase(git.fetch_head()) + + post_rebase(applied, options.nopush, options.merged) # maybe tidy up if config.get('stgit.keepoptimized') == 'yes': diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py index 2951421..63f18ec 100644 --- a/stgit/commands/rebase.py +++ b/stgit/commands/rebase.py @@ -49,19 +49,8 @@ def func(parser, options, args): check_conflicts() check_head_top_equal() - # pop all patches - applied = crt_series.get_applied() - if len(applied) > 0: - print 'Popping all applied patches...', - sys.stdout.flush() - crt_series.pop_patch(applied[0]) - print 'done' - - print 'Rebasing to "%s"...' % args[0] - git.reset(tree_id = git_id(args[0])) - - # push the patches back - if not options.nopush: - push_patches(applied, options.merged) + applied = prepare_rebase() + rebase(args[0]) + post_rebase(applied, options.nopush, options.merged) print_crt_patch() - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html