def get_changed_refs(self, refs, revs, force): new_refs = refs.copy() #The remote repo is empty and the local one doesn't have bookmarks/tags if refs.keys()[0] == 'capabilities^{}': del new_refs['capabilities^{}'] if not self.local_heads(): tip = hex(self.repo.lookup('tip')) bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True) bookmarks.setcurrent(self.repo, 'master') new_refs['refs/heads/master'] = self.map_git_get(tip) for rev in revs: ctx = self.repo[rev] heads = [t for t in ctx.tags() if t in self.local_heads()] tags = [t for t in ctx.tags() if t in self.tags] if not (heads or tags): raise hgutil.Abort("revision %s cannot be pushed since" " it doesn't have a ref" % ctx) for r in heads + tags: if r in heads: ref = 'refs/heads/'+r else: ref = 'refs/tags/'+r if ref not in refs: new_refs[ref] = self.map_git_get(ctx.hex()) elif new_refs[ref] in self._map_git: rctx = self.repo[self.map_hg_get(new_refs[ref])] if rctx.ancestor(ctx) == rctx or force: new_refs[ref] = self.map_git_get(ctx.hex()) else: raise hgutil.Abort("pushing %s overwrites %s" % (ref, ctx)) else: raise hgutil.Abort("%s changed on the server, please pull " "and merge before pushing" % ref) return new_refs
def get_changed_refs(self, refs, revs, force): new_refs = refs.copy() #The remote repo is empty and the local one doesn't have bookmarks/tags if refs.keys()[0] == 'capabilities^{}': del new_refs['capabilities^{}'] if not self.local_heads(): tip = hex(self.repo.lookup('tip')) bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True) bookmarks.setcurrent(self.repo, 'master') new_refs['refs/heads/master'] = self.map_git_get(tip) for rev in revs: ctx = self.repo[rev] heads = [t for t in ctx.tags() if t in self.local_heads()] tags = [t for t in ctx.tags() if t in self.tags] if not (heads or tags): 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 else: ref = 'refs/tags/'+r if ref not in refs: new_refs[ref] = self.map_git_get(ctx.hex()) elif new_refs[ref] in self._map_git: rctx = self.repo[self.map_hg_get(new_refs[ref])] if rctx.ancestor(ctx) == rctx or force: new_refs[ref] = self.map_git_get(ctx.hex()) 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) return new_refs