addremove: print meaningful error message if --similar not numeric
authorBryan O'Sullivan <bos@serpentine.com>
Sat, 21 Jul 2007 19:07:18 -0700
changeset 4966 8d982aef0be1
parent 4962 10afa3fab6b4
child 4967 cf67b5f3743d
child 4997 60c54154ec4c
addremove: print meaningful error message if --similar not numeric
mercurial/commands.py
tests/test-addremove-similar
tests/test-addremove-similar.out
--- a/mercurial/commands.py	Sat Jul 21 17:36:45 2007 +0200
+++ b/mercurial/commands.py	Sat Jul 21 19:07:18 2007 -0700
@@ -53,7 +53,10 @@
     between 0 (disabled) and 100 (files must be identical) as its
     parameter.  Detecting renamed files this way can be expensive.
     """
-    sim = float(opts.get('similarity') or 0)
+    try:
+        sim = float(opts.get('similarity') or 0)
+    except ValueError:
+        raise util.Abort(_('similarity must be a number'))
     if sim < 0 or sim > 100:
         raise util.Abort(_('similarity must be between 0 and 100'))
     return cmdutil.addremove(repo, pats, opts, similarity=sim/100.)
--- a/tests/test-addremove-similar	Sat Jul 21 17:36:45 2007 +0200
+++ b/tests/test-addremove-similar	Sat Jul 21 19:07:18 2007 -0700
@@ -41,3 +41,9 @@
 
 hg commit -m B
 
+echo % should all fail
+hg addremove -s foo
+hg addremove -s -1
+hg addremove -s 1e6
+
+true
--- a/tests/test-addremove-similar.out	Sat Jul 21 17:36:45 2007 +0200
+++ b/tests/test-addremove-similar.out	Sat Jul 21 19:07:18 2007 -0700
@@ -14,3 +14,7 @@
 removing large-file
 removing tiny-file
 recording removal of tiny-file as rename to small-file (82% similar)
+% should all fail
+abort: similarity must be a number
+abort: similarity must be between 0 and 100
+abort: similarity must be between 0 and 100