backout: allow backout of merge changeset with --parent option.

--parent allows to choose which parent of merge to revert to.
This commit is contained in:
Vadim Gelfer 2006-07-14 23:19:15 -07:00
parent 4bc0558c57
commit 895f59ec1c
2 changed files with 51 additions and 3 deletions

View File

@ -865,11 +865,22 @@ def backout(ui, repo, rev, **opts):
if op2 != nullid:
raise util.Abort(_('outstanding uncommitted merge'))
node = repo.lookup(rev)
parent, p2 = repo.changelog.parents(node)
if parent == nullid:
p1, p2 = repo.changelog.parents(node)
if p1 == nullid:
raise util.Abort(_('cannot back out a change with no parents'))
if p2 != nullid:
raise util.Abort(_('cannot back out a merge'))
if not opts['parent']:
raise util.Abort(_('cannot back out a merge changeset without '
'--parent'))
p = repo.lookup(opts['parent'])
if p not in (p1, p2):
raise util.Abort(_('%s is not a parent of %s' %
(short(p), short(node))))
parent = p
else:
if opts['parent']:
raise util.Abort(_('cannot use --parent on non-merge changeset'))
parent = p1
repo.update(node, force=True, show_stats=False)
revert_opts = opts.copy()
revert_opts['rev'] = hex(parent)
@ -2829,6 +2840,7 @@ table = {
('m', 'message', '', _('use <text> as commit message')),
('l', 'logfile', '', _('read commit message from <file>')),
('d', 'date', '', _('record datecode as commit date')),
('', 'parent', '', _('parent to choose when backing out merge')),
('u', 'user', '', _('record user as committer')),
('I', 'include', [], _('include names matching the given patterns')),
('X', 'exclude', [], _('exclude names matching the given patterns'))],

View File

@ -60,4 +60,40 @@ hg commit -d '2 0' -A -m c
hg backout -d '3 0' 1
hg locate b
cd ..
hg init m
cd m
echo a > a
hg commit -d '0 0' -A -m a
echo b > b
hg commit -d '1 0' -A -m b
echo c > c
hg commit -d '2 0' -A -m b
hg update 1
echo d > d
hg commit -d '3 0' -A -m c
hg merge 2
hg commit -d '4 0' -A -m d
echo '# backout of merge should fail'
hg backout 4
echo '# backout of merge with bad parent should fail'
hg backout --parent 0 4
echo '# backout of non-merge with parent should fail'
hg backout --parent 0 3
echo '# backout with valid parent should be ok'
hg backout -d '5 0' --parent 2 4
hg rollback
hg update -C
hg backout -d '6 0' --parent 3 4
exit 0