# HG changeset patch # User Navaneeth Suresh # Date 1553497421 -19800 # Node ID 03f6480bfddabb5d0faa817bd895d2b0437c472a # Parent 1711f5813a63cb6ae55ad6be66262763ee998c1f unshelve: disable unshelve during merge (issue5123) As stated in the issue5123, unshelve can destroy the second parent of the context when tried to unshelve with an uncommitted merge. This patch makes unshelve to abort when called with an uncommitted merge. See how shelve.mergefiles works. Commit structure looks like this: ``` ... -> pctx -> tmpwctx -> shelvectx / / second merge parent pctx = parent before merging working context(first merge parent) tmpwctx = commited working directory after merge(with two parents) shelvectx = shelved context ``` shelve.mergefiles first updates to pctx then it reverts shelvectx to pctx with: ``` cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(), *pathtofiles(repo, files), **{'no_backup': True}) ``` Reverting tmpwctx files that were merged from second parent to pctx makes them added because they are not in pctx. Changing this revert operation is crucial to restore parents after unshelve. This is a complicated issue as this is not fixing a regression. Thus, for the time being, unshelve during an uncommitted merge can be aborted. (Details taken from http://mercurial.808500.n3.nabble.com/PATCH-V3-shelve-restore-parents-after-unshelve-issue5123-tt4036858.html#a4037408) Differential Revision: https://phab.mercurial-scm.org/D6169 diff -r 1711f5813a63 -r 03f6480bfdda hgext/shelve.py --- a/hgext/shelve.py Mon Apr 01 20:01:48 2019 -0400 +++ b/hgext/shelve.py Mon Mar 25 12:33:41 2019 +0530 @@ -978,6 +978,12 @@ return unshelvecontinue(ui, repo, state, opts) elif len(shelved) > 1: raise error.Abort(_('can only unshelve one change at a time')) + + # abort unshelve while merging (issue5123) + parents = repo[None].parents() + if len(parents) > 1: + raise error.Abort(_('cannot unshelve while merging')) + elif not shelved: shelved = listshelves(repo) if not shelved: diff -r 1711f5813a63 -r 03f6480bfdda tests/test-shelve.t --- a/tests/test-shelve.t Mon Apr 01 20:01:48 2019 -0400 +++ b/tests/test-shelve.t Mon Mar 25 12:33:41 2019 +0530 @@ -1111,3 +1111,49 @@ test (4|13):33f7f61e6c5e (re) $ cd .. + +Abort unshelve while merging (issue5123) +---------------------------------------- + + $ hg init issue5123 + $ cd issue5123 + $ echo > a + $ hg ci -Am a + adding a + $ hg co null + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ echo > b + $ hg ci -Am b + adding b + created new head + $ echo > c + $ hg add c + $ hg shelve + shelved as default + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ hg co 1 + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 0 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) +-- successful merge with two parents + $ hg log -G + @ changeset: 1:406bf70c274f + tag: tip + parent: -1:000000000000 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: b + + @ changeset: 0:ada8c9eb8252 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: a + +-- trying to pull in the shelve bits +-- unshelve should abort otherwise, it'll eat my second parent. + $ hg unshelve + abort: cannot unshelve while merging + [255] + + $ cd ..