# HG changeset patch # User Matt Mackall # Date 2007-12-01 19:09:27 # Node ID de620356064ff9dcebcb77b8595c34b40368c332 # Parent 56e9f7b2d8fa73294bd9cf0d3826ce23e4b3c65c backout: disallow across branches (issue655) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -194,6 +194,11 @@ def backout(ui, repo, node=None, rev=Non if op2 != nullid: raise util.Abort(_('outstanding uncommitted merge')) node = repo.lookup(rev) + + a = repo.changelog.ancestor(op1, node) + if a != node: + raise util.Abort(_('cannot back out change on a different branch')) + p1, p2 = repo.changelog.parents(node) if p1 == nullid: raise util.Abort(_('cannot back out a change with no parents')) @@ -210,6 +215,7 @@ def backout(ui, repo, node=None, rev=Non if opts['parent']: raise util.Abort(_('cannot use --parent on non-merge changeset')) parent = p1 + hg.clean(repo, node, show_stats=False) revert_opts = opts.copy() revert_opts['date'] = None diff --git a/tests/test-backout b/tests/test-backout --- a/tests/test-backout +++ b/tests/test-backout @@ -37,6 +37,22 @@ echo '# backout of backout is as if noth hg backout -d '3 0' --merge tip cat a 2>/dev/null || echo cat: a: No such file or directory +echo '# across branch' +cd .. +hg init branch +cd branch +echo a > a +hg ci -Am0 -d '0 0' +echo b > b +hg ci -Am1 -d '0 0' +hg co -C 0 +# should fail +hg backout -d '0 0' 1 +echo c > c +hg ci -Am2 -d '0 0' +# should fail +hg backout -d '0 0' 1 + echo '# backout with merge' cd .. hg init merge diff --git a/tests/test-backout.out b/tests/test-backout.out --- a/tests/test-backout.out +++ b/tests/test-backout.out @@ -15,6 +15,13 @@ content removing a changeset 3:7f6d0f120113 backs out changeset 2:de31bdc76c0d cat: a: No such file or directory +# across branch +adding a +adding b +0 files updated, 0 files merged, 1 files removed, 0 files unresolved +abort: cannot back out change on a different branch +adding c +abort: cannot back out change on a different branch # backout with merge adding a reverting a