histedit: handle exceptions from node.bin in fromrule
authortimeless <timeless@mozdev.org>
Wed, 23 Dec 2015 23:51:29 +0000
changeset 27547 1cbfeb1dc5aa
parent 27546 c00924c54607
child 27548 435c906829b8
histedit: handle exceptions from node.bin in fromrule
hgext/histedit.py
tests/test-histedit-arguments.t
--- a/hgext/histedit.py	Wed Dec 23 23:23:28 2015 +0000
+++ b/hgext/histedit.py	Wed Dec 23 23:51:29 2015 +0000
@@ -356,7 +356,11 @@
         """Parses the given rule, returning an instance of the histeditaction.
         """
         rulehash = rule.strip().split(' ', 1)[0]
-        return cls(state, node.bin(rulehash))
+        try:
+            rev = node.bin(rulehash)
+        except TypeError:
+            raise error.ParseError("invalid changeset %s" % rulehash)
+        return cls(state, rev)
 
     def verify(self, prev):
         """ Verifies semantic correctness of the rule"""
--- a/tests/test-histedit-arguments.t	Wed Dec 23 23:23:28 2015 +0000
+++ b/tests/test-histedit-arguments.t	Wed Dec 23 23:51:29 2015 +0000
@@ -219,6 +219,17 @@
   hg: parse error: duplicated command for changeset eb57da33312f
   [255]
 
+Test bogus rev
+---------------------------------------
+
+  $ HGEDITOR=cat hg histedit "tip^^" --commands - << EOF
+  > pick eb57da33312f 2 three
+  > pick 0
+  > pick 08d98a8350f3 4 five
+  > EOF
+  hg: parse error: invalid changeset 0
+  [255]
+
 Test short version of command
 ---------------------------------------