From 64e15469e9ddf6e038b967beeae75c79d1a29460 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 28 Sep 2007 22:51:15 +0100 Subject: [PATCH] Fix the rebasing with an external command Since git.py caches the HEAD value, rebasing with and external command didn't clear the cache and the subsequent push simple fast-forwards the tree. The patch creates a new git.rebase() function which takes care of custom rebase commands. It also removes "must_rebase" in pull.py as it doesn't seem to be used. Signed-off-by: Catalin Marinas --- stgit/commands/common.py | 27 +++++++++------------------ stgit/commands/pull.py | 8 +------- stgit/git.py | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index d8323a82..9e1f7cbc 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -25,7 +25,6 @@ from stgit.utils import * from stgit.out import * from stgit import stack, git, basedir from stgit.config import config, file_extensions -from stgit.run import * crt_series = None @@ -34,11 +33,6 @@ crt_series = None class CmdException(Exception): pass -class CmdRunException(CmdException): - pass -class CmdRun(Run): - exc = CmdRunException - # Utility functions class RevParseException(Exception): """Revision spec parse error.""" @@ -340,23 +334,20 @@ def prepare_rebase(force=None): return applied def rebase(target): - if target == git.get_head(): + try: + tree_id = git_id(target) + except: + # it might be that we use a custom rebase command with its own + # target type + tree_id = target + if tree_id == git.get_head(): out.info('Already at "%s", no need for rebasing.' % target) return - command = config.get('branch.%s.stgit.rebasecmd' % git.get_head_file()) \ - or config.get('stgit.rebasecmd') if target: - args = [target] out.start('Rebasing to "%s"' % target) - elif command: - args = [] - out.start('Rebasing to the default target') - else: - raise CmdException, 'Default rebasing requires a target' - if command: - CmdRun(*(command.split() + args)).run() else: - git.reset(tree_id = git_id(target)) + out.start('Rebasing to the default target') + git.rebase(tree_id = tree_id) out.done() def post_rebase(applied, nopush, merged): diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py index ad485a5d..052ea2b6 100644 --- a/stgit/commands/pull.py +++ b/stgit/commands/pull.py @@ -78,13 +78,7 @@ def func(parser, options, args): check_conflicts() check_head_top_equal() - if policy == 'pull': - must_rebase = 0 - elif policy == 'fetch-rebase': - must_rebase = 1 - elif policy == 'rebase': - must_rebase = 1 - else: + if policy not in ['pull', 'fetch-rebase', 'rebase']: raise GitConfigException, 'Unsupported pull-policy "%s"' % policy applied = prepare_rebase(force=options.force) diff --git a/stgit/git.py b/stgit/git.py index d33227d8..9e0f7714 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -846,6 +846,27 @@ def pull(repository = 'origin', refspec = None): config.get('stgit.pullcmd') GRun(*(command.split() + args)).run() +def rebase(tree_id = None): + """Rebase the current tree to the give tree_id. The tree_id + argument may be something other than a GIT id if an external + command is invoked. + """ + command = config.get('branch.%s.stgit.rebasecmd' % get_head_file()) \ + or config.get('stgit.rebasecmd') + if tree_id: + args = [tree_id] + elif command: + args = [] + else: + raise GitException, 'Default rebasing requires a commit id' + if command: + # clear the HEAD cache as the custom rebase command will update it + __clear_head_cache() + GRun(*(command.split() + args)).run() + else: + # default rebasing + reset(tree_id = tree_id) + def repack(): """Repack all objects into a single pack """ -- 2.11.4.GIT