Patchwork histedit: abort gracefully on --continue/--abort with no state

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 4, 2014, 2:54 p.m.
Message ID <7b84fe4163b556e233cf.1409842445@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/5696/
State Accepted
Headers show

Comments

Siddharth Agarwal - Sept. 4, 2014, 2:54 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1409769771 -7200
#      Wed Sep 03 20:42:51 2014 +0200
# Node ID 7b84fe4163b556e233cfbd35750728c43bc6ea1a
# Parent  b21f3e34b117f72011f06cfb69d9114388258b50
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.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -149,6 +149,7 @@ 
     pickle.dump # import now
 except ImportError:
     import pickle
+import errno
 import os
 import sys
 
@@ -761,7 +762,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)
 
 
diff --git a/tests/test-histedit-arguments.t b/tests/test-histedit-arguments.t
--- a/tests/test-histedit-arguments.t
+++ b/tests/test-histedit-arguments.t
@@ -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.
 --------------------------------------------------------------------