histedit: abort gracefully on --continue/--abort with no state stable
authorSiddharth Agarwal <sid0@fb.com>
Wed, 03 Sep 2014 20:42:51 +0200
branchstable
changeset 22368 802dffd62de5
parent 22366 71227dc24311
child 22369 897041f6b025
child 22376 d821fff9b0b9
histedit: abort gracefully on --continue/--abort with no state Previously we'd print an ugly message saying that the histedit-state file doesn't exist in the repo.
hgext/histedit.py
tests/test-histedit-arguments.t
--- a/hgext/histedit.py	Tue Sep 02 03:41:01 2014 +0200
+++ b/hgext/histedit.py	Wed Sep 03 20:42:51 2014 +0200
@@ -147,6 +147,7 @@
     pickle.dump # import now
 except ImportError:
     import pickle
+import errno
 import os
 import sys
 
@@ -741,7 +742,12 @@
 def readstate(repo):
     """Returns a tuple of (parentnode, rules, keep, topmost, replacements).
     """
-    fp = open(os.path.join(repo.path, 'histedit-state'))
+    try:
+        fp = open(os.path.join(repo.path, 'histedit-state'))
+    except IOError, err:
+        if err.errno != errno.ENOENT:
+            raise
+        raise util.Abort(_('no histedit in progress'))
     return pickle.load(fp)
 
 
--- a/tests/test-histedit-arguments.t	Tue Sep 02 03:41:01 2014 +0200
+++ b/tests/test-histedit-arguments.t	Wed Sep 03 20:42:51 2014 +0200
@@ -41,6 +41,16 @@
        one
   
 
+histedit --continue/--abort with no existing state
+--------------------------------------------------
+
+  $ hg histedit --continue
+  abort: no histedit in progress
+  [255]
+  $ hg histedit --abort
+  abort: no histedit in progress
+  [255]
+
 Run a dummy edit to make sure we get tip^^ correctly via revsingle.
 --------------------------------------------------------------------