diff --git a/hgext/shelve.py b/hgext/shelve.py --- a/hgext/shelve.py +++ b/hgext/shelve.py @@ -683,22 +683,37 @@ _("unresolved conflicts, can't continue"), hint=_("see 'hg resolve', then 'hg unshelve --continue'")) - repo.vfs.rename('unshelverebasestate', 'rebasestate') - try: - rebase.rebase(ui, repo, **{ - r'continue' : True - }) - except Exception: - repo.vfs.rename('rebasestate', 'unshelverebasestate') - raise + shelvectx = repo[state.parents[1]] + pendingctx = state.pendingctx + + overrides = {('phases', 'new-commit'): phases.secret} + with repo.ui.configoverride(overrides, 'unshelve'): + with repo.dirstate.parentchange(): + repo.setparents(state.parents[0], nodemod.nullid) + newnode = repo.commit(text=shelvectx.description(), + extra=shelvectx.extra(), + user=shelvectx.user(), + date=shelvectx.date()) - shelvectx = repo['tip'] - if state.pendingctx not in shelvectx.parents(): - # rebase was a no-op, so it produced no child commit + if newnode is None: + # If it ended up being a no-op commit, then the normal + # merge state clean-up path doesn't happen, so do it + # here. Fix issue5494 + merge.mergestate.clean(repo) shelvectx = state.pendingctx + msg = _('note: unshelved changes already existed ' + 'in the working copy\n') + ui.status(msg) else: - # only strip the shelvectx if the rebase produced it - state.nodestoremove.append(shelvectx.node()) + # only strip the shelvectx if we produced one + state.nodestoremove.append(newnode) + shelvectx = repo[newnode] + + hg.updaterepo(repo, pendingctx.node(), False) + + if repo.vfs.exists('unshelverebasestate'): + repo.vfs.rename('unshelverebasestate', 'rebasestate') + rebase.clearstatus(repo) mergefiles(ui, repo, state.wctx, shelvectx) restorebranch(ui, repo, state.branchtorestore) diff --git a/tests/test-shelve.t b/tests/test-shelve.t --- a/tests/test-shelve.t +++ b/tests/test-shelve.t @@ -459,7 +459,6 @@ (continue: hg unshelve --continue) [255] $ hg unshelve -c - rebasing 5:32c69314e062 "changes to: [mq]: second.patch" (tip) unshelve of 'default' complete ensure the repo is as we hope @@ -901,8 +900,7 @@ (no more unresolved files) continue: hg unshelve --continue $ hg unshelve -c - rebasing 5:e42a7da90865 "changes to: second" (tip) - note: rebase of 5:e42a7da90865 created no changes to commit + note: unshelved changes already existed in the working copy unshelve of 'default' complete $ hg bookmark * test 4:33f7f61e6c5e @@ -1534,7 +1532,6 @@ (no more unresolved files) continue: hg unshelve --continue $ hg unshelve --continue - rebasing 2:425c97ef07f3 "changes to: a" (tip) marked working directory as branch test unshelve of 'default' complete $ cat a @@ -1618,7 +1615,6 @@ (no more unresolved files) continue: hg unshelve --continue $ hg unshelve --continue - rebasing 2:425c97ef07f3 "changes to: a" (tip) unshelve of 'default' complete $ cat a aaabbbccc @@ -1722,7 +1718,6 @@ (no more unresolved files) continue: hg unshelve --continue $ hg unshelve --continue - rebasing 2:3fbe6fbb0bef "changes to: 1" (tip) unshelve of 'default' complete $ hg shelve --list default (*s ago) * changes to: 1 (glob) @@ -1795,7 +1790,6 @@ continue: hg unshelve --continue mercurial does not crash $ hg unshelve --continue - rebasing 2:003d2d94241c "changes to: root" (tip) unshelve of 'ashelve' complete $ cd ..