From 1d5cfe617d97d943b41f4be17c4f5955a7026297 Mon Sep 17 00:00:00 2001 Message-Id: <1d5cfe617d97d943b41f4be17c4f5955a7026297.1715192409.git.mdw@distorted.org.uk> From: Mark Wooding Date: Thu, 27 Sep 2007 23:23:26 +0100 Subject: [PATCH] Allow the rebase command to be defined Organization: Straylight/Edgeware From: Catalin Marinas 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 --- examples/gitconfig | 5 +++++ stgit/commands/common.py | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/gitconfig b/examples/gitconfig index f181f82..52d2a69 100644 --- a/examples/gitconfig +++ b/examples/gitconfig @@ -46,6 +46,11 @@ #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: diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 8ed47ca..d8323a8 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -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): -- [mdw]