chiark / gitweb /
Allow the rebase command to be defined
authorCatalin Marinas <catalin.marinas@gmail.com>
Thu, 27 Sep 2007 22:23:26 +0000 (23:23 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 27 Sep 2007 22:23:26 +0000 (23:23 +0100)
This is useful if one wants to use StGIT on top of a Subversion
repository. After a "git svn clone" and "stg init", the following
options have to be defined to allow "stg pull" to work properly:

branch.master.remote = svn
stgit.pull-policy = fetch-rebase
stgit.fetchcmd = git svn fetch
stgit.rebasecmd = git svn rebase

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
examples/gitconfig
stgit/commands/common.py

index f181f8272919b822475a3ece951c91b0042f1027..52d2a696d5d0c004fa13c7327136f75f44655650 100644 (file)
        #pullcmd = git-pull
        #fetchcmd = git-fetch
 
+       # Rebase command. Note that this command is internally implemented in
+       # a different way. Only define this option if a different rebase
+       # is needed (i.e. 'git svn rebase')
+       #rebasecmd = git-reset
+
        # "stg pull" policy.  This is the repository default, which can be
        # overriden on a per-branch basis using branch.*.stgit.pull-policy
        # By default:
index 8ed47ca2645989929dc7a1df4190dd5d364c6aa6..d8323a823daa4962e33261cc4530a4ab38410dff 100644 (file)
@@ -25,6 +25,7 @@ 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
 
@@ -33,6 +34,10 @@ crt_series = None
 class CmdException(Exception):
     pass
 
+class CmdRunException(CmdException):
+    pass
+class CmdRun(Run):
+    exc = CmdRunException
 
 # Utility functions
 class RevParseException(Exception):
@@ -338,8 +343,20 @@ def rebase(target):
     if target == git.get_head():
         out.info('Already at "%s", no need for rebasing.' % target)
         return
-    out.start('Rebasing to "%s"' % target)
-    git.reset(tree_id = git_id(target))
+    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.done()
 
 def post_rebase(applied, nopush, merged):