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

Kostiantyn Balytskyi ikostia at fb.com
Fri Jul 1 13:19:11 EDT 2016


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1467391641 -7200
#      Fri Jul 01 18:47:21 2016 +0200
# Node ID 7b2a12a7d02a15a6b2f47015e1b01afa796bfcfc
# Parent  5b71a8d7f7ffc2662ceb58ad8eec806e147ae13d
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,16 @@ def _dounshelve(ui, repo, *shelved, **op
 
         try:
             state = shelvedstate.load(repo)
-        except IOError as err:
-            if err.errno != errno.ENOENT:
-                raise
-            cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+        except Exception as err:
+            if 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)
+            if isinstance(err, IOError) and err.errno == errno.ENOENT:
+                cmdutil.wrongtooltocontinue(repo, _('unshelve'))
+            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,26 @@ On non bare shelve the branch informatio
   ? b
   $ hg branch
   default
+  $ cd ..
+
+Unshelve --abort works 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
+  $ hg unshelve --abort
+  could not read shelved state file, your working copy may be in an unexpected state
+  please update to some commit
+  $ cd ..


More information about the Mercurial-devel mailing list