Patchwork [3,of,4] git: implement a basic checkconflict bookmark store method

login
register
mail settings
Submitter Josef 'Jeff' Sipek
Date March 26, 2020, 10:07 p.m.
Message ID <917cd2c4073cf69b2c36.1585260426@meili>
Download mbox | patch
Permalink /patch/45917/
State New
Headers show

Comments

Josef 'Jeff' Sipek - March 26, 2020, 10:07 p.m.
# HG changeset patch
# User Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
# Date 1585257894 14400
#      Thu Mar 26 17:24:54 2020 -0400
# Node ID 917cd2c4073cf69b2c366dccbfccc3b28ff4fca2
# Parent  c1b5ff87d07b7029f5df5345dbbc097a5f01d9b4
git: implement a basic checkconflict bookmark store method

It is heavily based on bmstore's own checkconflict.

Patch

diff --git a/hgext/git/__init__.py b/hgext/git/__init__.py
--- a/hgext/git/__init__.py
+++ b/hgext/git/__init__.py
@@ -219,6 +219,34 @@  class gitbmstore(object):
                     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):