Patchwork D9718: tests: add tests for corrupt .hg/shelved/ directory

login
register
mail settings
Submitter phabricator
Date Jan. 11, 2021, 6:04 p.m.
Message ID <differential-rev-PHID-DREV-f4c6lztres5fvvfvi6sk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48029/
State Superseded
Headers show

Comments

phabricator - Jan. 11, 2021, 6:04 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/test-shelve2.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t
--- a/tests/test-shelve2.t
+++ b/tests/test-shelve2.t
@@ -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*
+  .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*
+  .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: not enough values to unpack (expected 2, got 1)
+  $ hg unshelve 2>&1 | grep ValueError
+  ValueError: not enough values to unpack (expected 2, got 1)
+  $ hg shelve -d junk3
+  abort: shelved change 'junk3' not found
+  [255]
+  $ find .hg/shelve*
+  .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