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>
from stgit.out import *
from stgit import stack, git, basedir
from stgit.config import config, file_extensions
from stgit.out import *
from stgit import stack, git, basedir
from stgit.config import config, file_extensions
class CmdException(Exception):
pass
class CmdException(Exception):
pass
-class CmdRunException(CmdException):
- pass
-class CmdRun(Run):
- exc = CmdRunException
-
# Utility functions
class RevParseException(Exception):
"""Revision spec parse error."""
# Utility functions
class RevParseException(Exception):
"""Revision spec parse error."""
return applied
def rebase(target):
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
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')
out.start('Rebasing to "%s"' % 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()
- 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):
out.done()
def post_rebase(applied, nopush, merged):
check_conflicts()
check_head_top_equal()
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)
raise GitConfigException, 'Unsupported pull-policy "%s"' % policy
applied = prepare_rebase(force=options.force)
config.get('stgit.pullcmd')
GRun(*(command.split() + args)).run()
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
"""
def repack():
"""Repack all objects into a single pack
"""