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

login
register
mail settings
Submitter Laurent Charignon
Date Nov. 20, 2015, 6:31 p.m.
Message ID <5f16516ecbfcca33233f.1448044262@lcharignon-mbp.local>
Download mbox | patch
Permalink /patch/11544/
State Accepted
Headers show

Comments

Laurent Charignon - Nov. 20, 2015, 6:31 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@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.
Pierre-Yves David - Nov. 21, 2015, 12:39 a.m.
On 11/20/2015 10:31 AM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@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

Pushed to main, thanks.

Patch

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