changeset 46268:832a6a2efe4f

tests: add tests for corrupt .hg/shelved/ directory I don't care much how we behave in these cases, except that we should provide a way for the user to get out of the broken state. Differential Revision: https://phab.mercurial-scm.org/D9718
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 08 Jan 2021 16:38:41 -0800
parents b9b37418ac7e
children 44556639f14a
files tests/test-shelve2.t
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-shelve2.t	Wed Jan 13 18:29:19 2021 +0100
+++ b/tests/test-shelve2.t	Fri Jan 08 16:38:41 2021 -0800
@@ -745,6 +745,58 @@
 #endif
   $ cd ..
 
+Test corrupt shelves (in .hg/shelved/, not .hg/shelvestate)
+  $ hg init corrupt-shelves
+  $ cd corrupt-shelves
+  $ mkdir .hg/shelved
+
+# A (corrupt) .patch file without a .hg file
+  $ touch .hg/shelved/junk1.patch
+  $ hg shelve -l
+  junk1           (* ago)     (glob)
+  $ hg unshelve
+  unshelving change 'junk1'
+  abort: shelved change 'junk1' not found
+  [255]
+  $ hg shelve -d junk1
+  $ find .hg/shelve* | sort
+  .hg/shelve-backup
+  .hg/shelve-backup/junk1.patch
+  .hg/shelved
+
+# A .hg file without a .patch file
+  $ touch .hg/shelved/junk2.hg
+  $ hg shelve -l
+  $ hg unshelve
+  abort: no shelved changes to apply!
+  [255]
+  $ hg shelve -d junk2
+  abort: shelved change 'junk2' not found
+  [255]
+  $ find .hg/shelve* | sort
+  .hg/shelve-backup
+  .hg/shelve-backup/junk1.patch
+  .hg/shelve-backup/junk2.hg
+  .hg/shelved
+
+# A file with an unexpected extension
+  $ touch .hg/shelved/junk3
+  $ hg shelve -l 2>&1 | grep ValueError
+  ValueError: * (glob)
+  $ hg unshelve 2>&1 | grep ValueError
+  ValueError: * (glob)
+  $ hg shelve -d junk3
+  abort: shelved change 'junk3' not found
+  [255]
+  $ find .hg/shelve* | sort
+  .hg/shelve-backup
+  .hg/shelve-backup/junk1.patch
+  .hg/shelve-backup/junk2.hg
+  .hg/shelved
+  .hg/shelved/junk3
+
+  $ cd ..
+
 Unshelve respects --keep even if user intervention is needed
   $ hg init unshelvekeep && cd unshelvekeep
   $ echo 1 > file && hg ci -Am 1