git: implement a basic checkconflict bookmark store method
authorJosef 'Jeff' Sipek <jeffpc@josefsipek.net>
Thu, 26 Mar 2020 17:24:54 -0400
changeset 44623 bb3e05ca21ca
parent 44622 7bbb83e4e8de
child 44624 7cab8dbd0497
git: implement a basic checkconflict bookmark store method It is heavily based on bmstore's own checkconflict.
hgext/git/__init__.py
--- 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):