mercurial/commands.py
changeset 32482 579df5aaa425
parent 32451 bce5ebe72859
child 32486 1df80eff24cf
--- a/mercurial/commands.py	Thu May 25 23:18:02 2017 +0900
+++ b/mercurial/commands.py	Thu May 25 23:20:00 2017 +0900
@@ -968,11 +968,16 @@
             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 len(mark) > 3 and not force:
+            try:
+                shadowhash = (mark in repo)
+            except error.LookupError: # ambiguous identifier
+                shadowhash = False
+            if shadowhash:
+                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"))