diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -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 as commit message')), ('l', 'logfile', '', _('read commit message from ')), ('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'))],