changeset 44627:bb3e05ca21ca

git: implement a basic checkconflict bookmark store method It is heavily based on bmstore's own checkconflict.
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 26 Mar 2020 17:24:54 -0400
parents 7bbb83e4e8de
children 7cab8dbd0497
files hgext/git/__init__.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/git/__init__.py	Thu Mar 26 17:09:34 2020 -0400
+++ b/hgext/git/__init__.py	Thu Mar 26 17:24:54 2020 -0400
@@ -16,6 +16,7 @@
     extensions,
     localrepo,
     pycompat,
+    scmutil,
     store,
     util,
 )
@@ -219,6 +220,35 @@
                     force=True,
                 )
 
+    def checkconflict(self, mark, force=False, target=None):
+        githead = _BMS_PREFIX + mark
+        cur = self.gitrepo.references['HEAD']
+        if githead in self.gitrepo.references and not force:
+            if target:
+                if self.gitrepo.references[githead] == target and target == cur:
+                    # re-activating a bookmark
+                    return []
+                # moving a bookmark - forward?
+                raise NotImplementedError
+            raise error.Abort(
+                _(b"bookmark '%s' already exists (use -f to force)") % mark
+            )
+        if len(mark) > 3 and not force:
+            try:
+                shadowhash = scmutil.isrevsymbol(self._repo, mark)
+            except error.LookupError:  # ambiguous identifier
+                shadowhash = False
+            if shadowhash:
+                self._repo.ui.warn(
+                    _(
+                        b"bookmark %s matches a changeset hash\n"
+                        b"(did you leave a -r out of an 'hg bookmark' "
+                        b"command?)\n"
+                    )
+                    % mark
+                )
+        return []
+
 
 def init(orig, ui, dest=b'.', **opts):
     if opts.get('git', False):