D6596: unshelve: make unshelve accept files (issue6162)

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Thu Jul 11 09:06:21 EDT 2019


navaneeth.suresh updated this revision to Diff 15888.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6596?vs=15757&id=15888

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6596/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6596

AFFECTED FILES
  mercurial/commands.py
  mercurial/shelve.py
  tests/test-completion.t
  tests/test-shelve.t

CHANGE DETAILS

diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -1155,3 +1155,63 @@
   [255]
 
   $ cd ..
+
+-- make unshelve accept files
+
+  $ hg init a
+  $ cd a
+  $ echo > b
+  $ hg ci -Am b
+  adding b
+  $ echo > c
+  $ echo > d
+  $ hg add .
+  adding c
+  adding d
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ echo > e
+  $ hg add e
+  $ hg ci -m e
+  $ hg shelve --patch
+  default         (1s ago)    changes to: b
+  
+  diff --git a/c b/c
+  new file mode 100644
+  --- /dev/null
+  +++ b/c
+  @@ -0,0 +1,1 @@
+  +
+  diff --git a/d b/d
+  new file mode 100644
+  --- /dev/null
+  +++ b/d
+  @@ -0,0 +1,1 @@
+  +
+  $ hg unshelve -f c
+  unshelving change 'default'
+  rebasing shelved changes
+  $ ls
+  b
+  c
+  e
+-- shelve should not contain `c` now
+  $ hg shelve --patch
+  default         (1s ago)    changes to: b
+  
+  diff --git a/d b/d
+  new file mode 100644
+  --- /dev/null
+  +++ b/d
+  @@ -0,0 +1,1 @@
+  +
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  $ ls
+  b
+  c
+  d
+  e
+  $ hg shelve --list
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -349,7 +349,7 @@
   tags: template
   tip: patch, git, style, template
   unbundle: update
-  unshelve: abort, continue, keep, name, tool, date
+  unshelve: abort, continue, files, keep, name, tool, date
   update: clean, check, merge, date, rev, tool
   verify: full
   version: template
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -772,6 +772,7 @@
     """Rebase restored commit from its original location to a destination"""
     # If the shelve is not immediately on top of the commit
     # we'll be merging with, rebase it to be on top.
+    filesinclude = opts.get('files', [])
     if tmpwctx.node() == shelvectx.p1().node():
         return shelvectx
 
@@ -797,10 +798,19 @@
 
         with repo.dirstate.parentchange():
             repo.setparents(tmpwctx.node(), nodemod.nullid)
+            m = scmutil.match(shelvectx, filesinclude, {})
             newnode = repo.commit(text=shelvectx.description(),
                                   extra=shelvectx.extra(),
                                   user=shelvectx.user(),
-                                  date=shelvectx.date())
+                                  date=shelvectx.date(),
+                                  match=m)
+            if filesinclude:
+                snode = repo.commit(text=shelvectx.description(),
+                                    extra=shelvectx.extra(),
+                                    user=shelvectx.user(),
+                                    date=shelvectx.date())
+                m = scmutil.matchfiles(repo, repo[snode].files())
+                _shelvecreatedcommit(repo, snode, basename, m)
 
         if newnode is None:
             # If it ended up being a no-op commit, then the normal
@@ -938,6 +948,8 @@
         if shelvectx.branch() != shelvectx.p1().branch():
             branchtorestore = shelvectx.branch()
 
+        allfiles = shelvectx.files()
+        filesinclude = opts.get('files', [])
         shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev,
                                           basename, pctx, tmpwctx,
                                           shelvectx, branchtorestore,
@@ -946,11 +958,12 @@
         with ui.configoverride(overrides, 'unshelve'):
             mergefiles(ui, repo, pctx, shelvectx)
         restorebranch(ui, repo, branchtorestore)
-        _forgetunknownfiles(repo, shelvectx, addedbefore)
+        if not filesinclude or (filesinclude and allfiles == filesinclude):
+            _forgetunknownfiles(repo, shelvectx, addedbefore)
 
-        shelvedstate.clear(repo)
-        _finishunshelve(repo, oldtiprev, tr, activebookmark)
-        unshelvecleanup(ui, repo, basename, opts)
+            shelvedstate.clear(repo)
+            _finishunshelve(repo, oldtiprev, tr, activebookmark)
+            unshelvecleanup(ui, repo, basename, opts)
     finally:
         if tr:
             tr.release()
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6158,6 +6158,8 @@
            _('abort an incomplete unshelve operation')),
           ('c', 'continue', None,
            _('continue an incomplete unshelve operation')),
+          ('f', 'files', [],
+           _('perform unshelve on selected files'), _('FILE')),
           ('k', 'keep', None,
            _('keep shelve after unshelving')),
           ('n', 'name', '',
@@ -6165,7 +6167,7 @@
           ('t', 'tool', '', _('specify merge tool')),
           ('', 'date', '',
            _('set date for temporary commits (DEPRECATED)'), _('DATE'))],
-         _('hg unshelve [[-n] SHELVED]'),
+         _('hg unshelve [-f FILE] [-n SHELVED]'),
          helpcategory=command.CATEGORY_WORKING_DIRECTORY)
 def unshelve(ui, repo, *shelved, **opts):
     """restore a shelved change to the working directory



To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, mercurial-devel


More information about the Mercurial-devel mailing list