chiark / gitweb /
Fix the rebasing with an external command
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 28 Sep 2007 21:51:15 +0000 (22:51 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 28 Sep 2007 21:51:15 +0000 (22:51 +0100)
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 <catalin.marinas@gmail.com>
stgit/commands/common.py
stgit/commands/pull.py
stgit/git.py

index d8323a823daa4962e33261cc4530a4ab38410dff..9e1f7cbc74d05ee23dd3c658d4559635a361b2bf 100644 (file)
@@ -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):
index ad485a5dfd25eb50e04e3001122d19649b9ec3d2..052ea2b6de47ea09d12f218bb9d137f47edf2faa 100644 (file)
@@ -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)
index d33227d80dc892b09ad9fffd7a137e877b227d15..9e0f7714f9d48c35d5dc6e718486b4fa7ee2d631 100644 (file)
@@ -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
     """