Mercurial > hg-stable
changeset 2614:8ba1c31f6864
backout: allow backout of merge changeset with --parent option.
--parent allows to choose which parent of merge to revert to.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 14 Jul 2006 23:19:15 -0700 |
parents | 479e26afa10f |
children | 114790d3a081 |
files | mercurial/commands.py tests/test-backout |
diffstat | 2 files changed, 51 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Fri Jul 14 14:51:36 2006 -0700 +++ b/mercurial/commands.py Fri Jul 14 23:19:15 2006 -0700 @@ -865,11 +865,22 @@ 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 @@ ('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'))],
--- a/tests/test-backout Fri Jul 14 14:51:36 2006 -0700 +++ b/tests/test-backout Fri Jul 14 23:19:15 2006 -0700 @@ -60,4 +60,40 @@ 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