[PATCH evolve-ext] inhibit: improve handling of error cases for bookmark -D

Laurent Charignon lcharignon at fb.com
Fri Nov 20 18:31:02 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1448044242 28800
#      Fri Nov 20 10:30:42 2015 -0800
# Node ID 5f16516ecbfcca33233fb61623836d8f7008299a
# Parent  48547b4c77defdd17c670b1eb0eb94272edf0207
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.

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -85,6 +85,11 @@ def _bookmark(orig, ui, repo, *bookmarks
     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')
diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -305,6 +305,16 @@ that are not reachable from another book
   |
   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


More information about the Mercurial-devel mailing list