From c1628cc3174f24e0a10d5db50461a889c346dd3c Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Thu, 19 Dec 2024 18:19:53 -0800 Subject: [PATCH] bookmark: check input looks like hash for "missing -r" warning Summary: Check that the bookmark name looks like a commit hash before we warn about the bookmark name looking like a commit hash. This avoids spurious warnings when creating a local bookmark with the same name as a remote bookmark (i.e. tracking bookmark). Reviewed By: zzl0 Differential Revision: D67464491 fbshipit-source-id: 87c00fcfd5b4e41a37dc6d9316ba168cce0cf3cc --- eden/scm/sapling/bookmarks.py | 3 ++- eden/scm/tests/test-bookmarks.t | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/eden/scm/sapling/bookmarks.py b/eden/scm/sapling/bookmarks.py index 054ac3c5bd60f..a8e574cb2ed28 100644 --- a/eden/scm/sapling/bookmarks.py +++ b/eden/scm/sapling/bookmarks.py @@ -13,6 +13,7 @@ from __future__ import absolute_import import errno +import string import struct import typing @@ -250,7 +251,7 @@ def checkconflict(self, mark, force=False, target=None): raise error.Abort( _("bookmark '%s' already exists (use -f to force)") % mark ) - if len(mark) > 3 and not force: + if len(mark) > 3 and not force and all(c in string.hexdigits for c in mark): try: shadowhash = mark in self._repo except error.LookupError: # ambiguous identifier diff --git a/eden/scm/tests/test-bookmarks.t b/eden/scm/tests/test-bookmarks.t index 371fee11ed83c..9e34d6223e7a2 100644 --- a/eden/scm/tests/test-bookmarks.t +++ b/eden/scm/tests/test-bookmarks.t @@ -346,11 +346,9 @@ bookmark with existing name abort: bookmark 'Z' already exists (use -f to force) [255] -bookmark with name of branch +bookmark with name of branch (allowed - branches are deprecated) $ hg bookmark default - bookmark default matches a changeset hash - (did you leave a -r out of an 'hg bookmark' command?) $ hg bookmark -f default $ hg book -d default @@ -373,6 +371,10 @@ bookmark with a name that matches a node id test-hook-bookmark: db815d6d32e6: -> db815d6d32e69058eadefc8cffbad37675707975 $ hg bookmark -d 925d80f479bb $ hg bookmark -d db815d6d32e6 +Don't warn if name clearly isn't a hex node. + $ hg push --to remote-bookmark-name --create -q + $ hg bookmark remote-bookmark-name + $ hg book -d remote-bookmark-name $ cd ..