changeset 32451:bce5ebe72859

bookmarks: warn about bookmark names that unambiguously resolve to a node (BC) I just burned myself on this today because I left out the -r in my `hg bookmark` command, which then left me confused because I didn't notice the bookmark I created in the wrong place that was silently shadowing the revision I was trying to check out. Let's warn the user. This patch only enforces the check on bookmark names 4 characters long or longer. We can tweak that if we'd like, I selected that since that's the fewest characters shortest will use in the templater output. A previous version of this patch rejected such bookmarks. It was proposed during review (and I agree) that the behavior change for a bookmark named "cafe" or similar as history accumulated was a little too weird, but that the warning definitely has merit.
author Augie Fackler <augie@google.com>
date Mon, 22 May 2017 19:18:12 -0400
parents 548478efc46c
children b647b923486f
files mercurial/commands.py tests/test-bookmarks.t
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu May 04 11:51:07 2017 +0900
+++ b/mercurial/commands.py	Mon May 22 19:18:12 2017 -0400
@@ -968,6 +968,11 @@
             and not force):
             raise error.Abort(
                 _("a bookmark cannot have the name of an existing branch"))
+        if len(mark) > 3 and mark in repo and not force:
+            repo.ui.warn(
+                _("bookmark %s matches a changeset hash\n"
+                  "(did you leave a -r out of an 'hg bookmark' command?)\n") %
+                mark)
 
     if delete and rename:
         raise error.Abort(_("--delete and --rename are incompatible"))
--- a/tests/test-bookmarks.t	Thu May 04 11:51:07 2017 +0900
+++ b/tests/test-bookmarks.t	Mon May 22 19:18:12 2017 -0400
@@ -311,6 +311,15 @@
   abort: cannot use an integer as a name
   [255]
 
+bookmark with a name that matches a node id
+  $ hg bookmark 925d80f479bb db815d6d32e6
+  bookmark 925d80f479bb matches a changeset hash
+  (did you leave a -r out of an 'hg bookmark' command?)
+  bookmark db815d6d32e6 matches a changeset hash
+  (did you leave a -r out of an 'hg bookmark' command?)
+  $ hg bookmark -d 925d80f479bb
+  $ hg bookmark -d db815d6d32e6
+
 incompatible options
 
   $ hg bookmark -m Y -d Z