inhibit: improve handling of error cases for bookmark -D
authorLaurent Charignon <lcharignon@fb.com>
Fri, 20 Nov 2015 10:30:42 -0800
changeset 1538 ef5da2310398
parent 1537 50e683d9835e
child 1539 72f50a177806
inhibit: improve handling of error cases for bookmark -D Before this patch bookmark -D was crashing in some cases like: hg book -Dmaster-fix. This was because -m is a valid option for hg bookmark. This patch disallows using -m with -D (moving and pruning does not make much sense) and throws an error instead of crashing if the command is malformed.
hgext/inhibit.py
tests/test-inhibit.t
--- a/hgext/inhibit.py	Wed Nov 18 13:47:26 2015 -0800
+++ b/hgext/inhibit.py	Fri Nov 20 10:30:42 2015 -0800
@@ -85,6 +85,11 @@
     haspruneopt = opts.get('prune', False)
     if not haspruneopt:
         return orig(ui, repo, *bookmarks, **opts)
+    elif opts.get('rename'):
+        raise util.Abort('Cannot use both -m and -D')
+    elif len(bookmarks) == 0:
+        hint = _('make sure to put a space between -D and your bookmark name')
+        raise util.Abort(_('Error, please check your command'), hint=hint)
 
     # Call prune -B
     evolve = extensions.find('evolve')
--- a/tests/test-inhibit.t	Wed Nov 18 13:47:26 2015 -0800
+++ b/tests/test-inhibit.t	Fri Nov 20 10:30:42 2015 -0800
@@ -305,6 +305,16 @@
   |
   o  0:54ccbc537fc2 add cA
   
+Test edge cases of bookmark -D
+  $ hg book -D book2 -m hello
+  abort: Cannot use both -m and -D
+  [255]
+
+  $ hg book -Draster-fix
+  abort: Error, please check your command
+  (make sure to put a space between -D and your bookmark name)
+  [255]
+
 Test that direct access make changesets visible
 
   $ hg export 2db36d8066ff 02bcbc3f6e56