# HG changeset patch # User timeless # Date 2016-02-05 01:56:46 # Node ID 61f4d59e9a0be4e25c1aa016db1a80a540a9d337 # Parent b19d8d5d6b514c90d37204020f0935bd97fa4d1f rebase: update working directory when aborting (issue5084) diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -975,15 +975,20 @@ def abort(repo, originalwd, target, stat cleanup = False if cleanup: + shouldupdate = False + rebased = filter(lambda x: x >= 0 and x != target, state.values()) + if rebased: + strippoints = [ + c.node() for c in repo.set('roots(%ld)', rebased)] + shouldupdate = len([ + c.node() for c in repo.set('. & (%ld)', rebased)]) > 0 + # Update away from the rebase if necessary - if needupdate(repo, state): + if shouldupdate or needupdate(repo, state): merge.update(repo, originalwd, False, True) # Strip from the first rebased revision - rebased = filter(lambda x: x >= 0 and x != target, state.values()) if rebased: - strippoints = [ - c.node() for c in repo.set('roots(%ld)', rebased)] # no backup of rebased cset versions needed repair.strip(repo.ui, repo, strippoints) diff --git a/tests/failfilemerge.py b/tests/failfilemerge.py new file mode 100644 --- /dev/null +++ b/tests/failfilemerge.py @@ -0,0 +1,18 @@ +# extension to emulate interupting filemerge._filemerge + +from __future__ import absolute_import + +from mercurial import ( + filemerge, + extensions, + error, +) + +def failfilemerge(filemergefn, + premerge, repo, mynode, orig, fcd, fco, fca, labels=None): + raise error.Abort("^C") + return filemergefn(premerge, repo, mynode, orig, fcd, fco, fca, labels) + +def extsetup(ui): + extensions.wrapfunction(filemerge, '_filemerge', + failfilemerge) diff --git a/tests/test-rebase-abort.t b/tests/test-rebase-abort.t --- a/tests/test-rebase-abort.t +++ b/tests/test-rebase-abort.t @@ -323,6 +323,78 @@ user has somehow managed to update to a $ cd .. +test aborting an interrupted series (issue5084) + $ hg init interrupted + $ cd interrupted + $ touch base + $ hg add base + $ hg commit -m base + $ touch a + $ hg add a + $ hg commit -m a + $ echo 1 > a + $ hg commit -m 1 + $ touch b + $ hg add b + $ hg commit -m b + $ echo 2 >> a + $ hg commit -m c + $ touch d + $ hg add d + $ hg commit -m d + $ hg co -q 1 + $ hg rm a + $ hg commit -m no-a + created new head + $ hg co 0 + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg log -G --template "{rev} {desc} {bookmarks}" + o 6 no-a + | + | o 5 d + | | + | o 4 c + | | + | o 3 b + | | + | o 2 1 + |/ + o 1 a + | + @ 0 base + + $ hg --config extensions.n=$TESTDIR/failfilemerge.py rebase -s 3 -d tip + rebasing 3:3a71550954f1 "b" + rebasing 4:e80b69427d80 "c" + abort: ^C + [255] + $ hg rebase --abort + saved backup bundle to $TESTTMP/interrupted/.hg/strip-backup/3d8812cf300d-93041a90-backup.hg (glob) + rebase aborted + $ hg log -G --template "{rev} {desc} {bookmarks}" + o 6 no-a + | + | o 5 d + | | + | o 4 c + | | + | o 3 b + | | + | o 2 1 + |/ + o 1 a + | + @ 0 base + + $ hg summary + parent: 0:df4f53cec30a + base + branch: default + commit: (clean) + update: 6 new changesets (update) + phases: 7 draft + + $ cd .. On the other hand, make sure we *do* clobber changes whenever we haven't somehow managed to update the repo to a different revision during a rebase (issue4661)