changeset 310:53b0d608dcd5

when pushing, check if server is advertising annotated tags Check if already we have these annotated tags; if so, don't push it. Update test-git-tags too.
author Tay Ray Chuan <rctay89@gmail.com>
date Mon, 15 Mar 2010 12:53:54 +0800
parents af8d8fbc8025
children b1d6c7fe2f81
files hggit/git_handler.py tests/test-git-tags.out
diffstat 2 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py	Mon Mar 15 13:10:06 2010 +0800
+++ b/hggit/git_handler.py	Mon Mar 15 12:53:54 2010 +0800
@@ -568,6 +568,30 @@
                 raise hgutil.Abort("revision %s cannot be pushed since"
                                    " it doesn't have a ref" % ctx)
 
+            # Check if the tags the server is advertising are annotated tags,
+            # by attempting to retrieve it from the our git repo, and building a
+            # list of these tags.
+            #
+            # This is possible, even though (currently) annotated tags are
+            # dereferenced and stored as lightweight ones, as the annotated tag
+            # is still stored in the git repo.
+            uptodate_annotated_tags = []
+            for r in tags:
+                ref = 'refs/tags/'+r
+                # Check tag.
+                if not ref in refs:
+                    continue
+                try:
+                    # We're not using Repo.tag(), as it's deprecated.
+                    tag = self.git.get_object(refs[ref])
+                    if not isinstance(tag, Tag):
+                        continue
+                except KeyError:
+                    continue
+
+                # If we've reached here, the tag's good.
+                uptodate_annotated_tags.append(ref)
+
             for r in heads + tags:
                 if r in heads:
                     ref = 'refs/heads/'+r
@@ -583,6 +607,9 @@
                     else:
                         raise hgutil.Abort("pushing %s overwrites %s"
                                            % (ref, ctx))
+                elif ref in uptodate_annotated_tags:
+                    # we already have the annotated tag.
+                    pass
                 else:
                     raise hgutil.Abort("%s changed on the server, please pull "
                                        "and merge before pushing" % ref)
--- a/tests/test-git-tags.out	Mon Mar 15 13:10:06 2010 +0800
+++ b/tests/test-git-tags.out	Mon Mar 15 12:53:54 2010 +0800
@@ -24,4 +24,6 @@
 pushing to git://localhost/gitrepo
 importing Hg objects into Git
 creating and sending data
-abort: refs/tags/beta changed on the server, please pull and merge before pushing
+    default::refs/tags/beta => GIT:e6f255c6
+    default::refs/tags/alpha => GIT:7eeab2ea
+    default::refs/heads/master => GIT:3b7fd1b3