[PATCH v2] shelve: make unshelve be able to abort in any case

Kostia Balytskyi ikostia at fb.com
Thu Jul 7 17:12:41 EDT 2016


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1467925588 -7200
#      Thu Jul 07 23:06:28 2016 +0200
# Node ID f06ece8d99297bb9e3e8446be6bedff66acbb831
# Parent  b4d117cee636be8a566f56e84d4b351a736a1299
shelve: make unshelve be able to abort in any case

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -662,10 +662,23 @@ def _dounshelve(ui, repo, *shelved, **op
 
         try:
             state = shelvedstate.load(repo)
+        except error.HintException:
+            raise
         except IOError as err:
-            if err.errno != errno.ENOENT:
-                raise
-            cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+            if err.errno == errno.ENOENT:
+                cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+        except Exception as err:
+            if continuef:
+                msg = _('could not read shelved state file\nplease run '
+                        'hg unshelve --abort to abort unshelve operation\n')
+                raise error.Abort(msg)
+            elif abortf:
+                msg = _('could not read shelved state file, your working copy '
+                        'may be in an unexpected state\nplease update to some '
+                        'commit\n')
+                ui.warn(msg)
+                shelvedstate.clear(repo)
+            return
 
         if abortf:
             return unshelveabort(ui, repo, state, opts)
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -1585,3 +1585,41 @@ On non bare shelve the branch informatio
   ? b
   $ hg branch
   default
+  $ cd ..
+
+Prepare unshleve with a corrupted shelvedstate
+  $ hg init r1 && cd r1
+  $ echo text1 > file && hg add file
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo text2 > file && hg ci -Am text1
+  adding file
+  $ hg unshelve
+  unshelving change 'default'
+  rebasing shelved changes
+  rebasing 1:396ea74229f9 "(changes in empty repository)" (tip)
+  merging file
+  warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+  $ echo somethingsomething > .hg/shelvedstate
+
+Unshelve --continue fails with appropriate message if shelvedstate is corrupted
+  $ hg unshelve --continue
+  abort: could not read shelved state file
+  please run hg unshelve --abort to abort unshelve operation
+  
+  [255]
+
+Unshelve --abort works with a corrupted shelvedstate
+  $ hg unshelve --abort
+  could not read shelved state file, your working copy may be in an unexpected state
+  please update to some commit
+
+Unshelve --abort fails with appropriate message if there's no unshelve in
+progress
+  $ hg unshelve --abort
+  abort: no unshelve in progress
+  [255]
+  $ cd ..


More information about the Mercurial-devel mailing list