chiark / gitweb /
Allow the rebase command to be defined
[stgit] / stgit / commands / common.py
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):