shelve: fix crash on unshelve without .shelve metadata file
authorYuya Nishihara <yuya@tcha.org>
Fri, 31 Aug 2018 21:10:28 +0900
changeset 39387 da84cca65036
parent 39386 2df3271ef139
child 39388 ddfd80029306
shelve: fix crash on unshelve without .shelve metadata file Follow up for c67c94c0e7ae and 38373da1af02. The inline comment says "we should keep track of the unshelve node in case we need to reuse it." Perhaps such case isn't tested, and this patch does NOT add a test for the reuse of the unbundled revision. Also, I have no idea what should be done if new revision is unbundled because of "node not in repo".
hgext/shelve.py
tests/test-shelve.t
--- a/hgext/shelve.py	Sat Sep 01 10:40:48 2018 +0900
+++ b/hgext/shelve.py	Fri Aug 31 21:10:28 2018 +0900
@@ -765,6 +765,7 @@
 def _unshelverestorecommit(ui, repo, basename):
     """Recreate commit in the repository during the unshelve"""
     repo = repo.unfiltered()
+    node = None
     if shelvedfile(repo, basename, 'shelve').exists():
         node = shelvedfile(repo, basename, 'shelve').readinfo()['node']
     if node is None or node not in repo:
@@ -774,7 +775,7 @@
         # We might not strip the unbundled changeset, so we should keep track of
         # the unshelve node in case we need to reuse it (eg: unshelve --keep)
         if node is None:
-            info = {'node': nodemod.hex(node)}
+            info = {'node': nodemod.hex(shelvectx.node())}
             shelvedfile(repo, basename, 'shelve').writeinfo(info)
     else:
         shelvectx = repo[node]
--- a/tests/test-shelve.t	Sat Sep 01 10:40:48 2018 +0900
+++ b/tests/test-shelve.t	Fri Aug 31 21:10:28 2018 +0900
@@ -1793,5 +1793,23 @@
 mercurial does not crash
   $ hg unshelve --continue
   unshelve of 'ashelve' complete
+
+Unshelve without .shelve metadata:
+
+  $ hg shelve
+  shelved as default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ rm .hg/shelved/default.shelve
+  $ echo 3 > a
+  $ 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]
+  $ cat .hg/shelved/default.shelve
+  node=82e0cb9893247d12667017593ce1e5655860f1ac
+
   $ cd ..
-