# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 2019-03-22 15:26:47 # Node ID 50d5e64ec561a8227ad32fe86c1811963e7664cd # Parent 9b78bbb761118802df2e0f3a88d57f553cb82c6d shelve: do not update when keeping changes, just move the dirstate This is to leave the working directory unchanged. We reuse the match object as an optimisation. diff --git a/hgext/shelve.py b/hgext/shelve.py --- a/hgext/shelve.py +++ b/hgext/shelve.py @@ -499,14 +499,19 @@ def _docreatecmd(ui, repo, pats, opts): return 1 # Create a matcher so that prefetch doesn't attempt to fetch - # the entire repository pointlessly + # the entire repository pointlessly, and as an optimisation + # for movedirstate, if needed. match = scmutil.matchfiles(repo, repo[node].files()) _shelvecreatedcommit(repo, node, name, match) if ui.formatted(): desc = stringutil.ellipsis(desc, ui.termwidth()) ui.status(_('shelved as %s\n') % name) - hg.update(repo, parent.node()) + if opts['keep']: + with repo.dirstate.parentchange(): + scmutil.movedirstate(repo, parent, match) + else: + hg.update(repo, parent.node()) if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts): repo.dirstate.setbranch(origbranch) diff --git a/tests/test-shelve.t b/tests/test-shelve.t --- a/tests/test-shelve.t +++ b/tests/test-shelve.t @@ -928,6 +928,20 @@ with general delta Stream params: {Compression: BZ} changegroup -- {nbchanges: 1, version: 02} (mandatory: True) 330882a04d2ce8487636b1fb292e5beea77fa1e3 + +Test shelve --keep + + $ hg unshelve + unshelving change 'default' + $ hg shelve --keep + shelved as default + $ hg diff + diff --git a/jungle b/jungle + new file mode 100644 + --- /dev/null + +++ b/jungle + @@ -0,0 +1,1 @@ + +babar $ cd .. Test visibility of in-memory changes inside transaction to external hook