changeset 39894:d9ba836fc234

shelve: find shelvedctx from bundle even if they are already in the repo We use the new "duplicates" node tracking to find the tip of the bundle even if it already exists in the repository. Such logic is not supposed to be needed in theory. If the shelve was made using internal-phase, we already know its node. Otherwise, the bundle content should have been stripped. However, handling it makes the shelve code more robust and provide a good example of "revduplicates" usage.
author Boris Feld <boris.feld@octobus.net>
date Thu, 20 Sep 2018 17:47:05 +0200
parents 42a6b228dd2e
children 1c3f1491965f
files hgext/shelve.py tests/test-shelve.t
diffstat 2 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/shelve.py	Wed Sep 19 12:19:28 2018 +0200
+++ b/hgext/shelve.py	Thu Sep 20 17:47:05 2018 +0200
@@ -144,11 +144,17 @@
             if not phases.supportinternal(self.repo):
                 targetphase = phases.secret
             gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
-            bundle2.applybundle(self.repo, gen, self.repo.currenttransaction(),
+            pretip = self.repo['tip']
+            tr = self.repo.currenttransaction()
+            bundle2.applybundle(self.repo, gen, tr,
                                 source='unshelve',
                                 url='bundle:' + self.vfs.join(self.fname),
                                 targetphase=targetphase)
-            return self.repo['tip']
+            shelvectx = self.repo['tip']
+            if pretip == shelvectx:
+                shelverev = tr.changes['revduplicates'][-1]
+                shelvectx = self.repo[shelverev]
+            return shelvectx
         finally:
             fp.close()
 
--- a/tests/test-shelve.t	Wed Sep 19 12:19:28 2018 +0200
+++ b/tests/test-shelve.t	Thu Sep 20 17:47:05 2018 +0200
@@ -1858,16 +1858,34 @@
 
 #if phasebased
 
-Unshelve without .shelve metadata:
+Unshelve with some metadata file missing
+----------------------------------------
 
   $ hg shelve
   shelved as default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo 3 > a
+
+Test with the `.shelve` missing, but the changeset still in the repo (non-natural case)
+
+  $ rm .hg/shelved/default.shelve
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging a
+  warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ hg unshelve --abort
+  unshelve of 'default' aborted
+
+Unshelve without .shelve metadata (can happen when upgrading a repository with old shelve)
+
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
   $ hg strip --hidden --rev 82e0cb989324 --no-backup
   $ rm .hg/shelved/default.shelve
-  $ echo 3 > a
   $ hg unshelve
   unshelving change 'default'
   temporarily committing pending changes (restore with 'hg unshelve --abort')
@@ -1878,6 +1896,8 @@
   [1]
   $ cat .hg/shelved/default.shelve
   node=82e0cb9893247d12667017593ce1e5655860f1ac
+  $ hg unshelve --abort
+  unshelve of 'default' aborted
 
 #endif