Mercurial > hg-git
view hggit/gitrepo.py @ 1102:93cb29247d61
exchange: check for remote refs to determine if we're cloning
The exchange.pull wrapper function was checking whether any paths were
configured yet as a proxy to determine whether we're doing the initial
clone or a subsequent pull. Core hg @ bdae51a83dfb (released in 4.5) now
sets the 'default' path on the ui object before exchange.pull is called,
but we can check a bit more directly by checking if we have any remote
refs yet. This is the same as a check we do in GitHandler.fetch_pack().
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Sat, 03 Feb 2018 14:54:35 -0600 |
parents | 5e49230a6cd5 |
children | 8ed6c0cae9b8 |
line wrap: on
line source
from util import isgitsshuri from mercurial import util from mercurial.error import RepoError peerapi = False try: from mercurial.repository import peer as peerrepository peerapi = True except ImportError: from mercurial.peer import peerrepository class gitrepo(peerrepository): def __init__(self, ui, path, create): if create: # pragma: no cover raise util.Abort('Cannot create a git repository.') self._ui = ui self.path = path self.localrepo = None _peercapabilities = ['lookup'] def _capabilities(self): return self._peercapabilities def capabilities(self): return self._peercapabilities @property def ui(self): return self._ui def url(self): return self.path def lookup(self, key): if isinstance(key, str): return key def local(self): if not self.path: raise RepoError def heads(self): return [] def listkeys(self, namespace): if namespace == 'namespaces': return {'bookmarks': ''} elif namespace == 'bookmarks': if self.localrepo is not None: handler = self.localrepo.githandler result = handler.fetch_pack(self.path, heads=[]) # map any git shas that exist in hg to hg shas stripped_refs = { ref[11:]: handler.map_hg_get(val) or val for ref, val in result.refs.iteritems() if ref.startswith('refs/heads/') } return stripped_refs return {} def pushkey(self, namespace, key, old, new): return False if peerapi: def branchmap(self): raise NotImplementedError def canpush(self): return True def close(self): pass def debugwireargs(self): raise NotImplementedError def getbundle(self): raise NotImplementedError def iterbatch(self): raise NotImplementedError def known(self): raise NotImplementedError def peer(self): return self def stream_out(self): raise NotImplementedError def unbundle(self): raise NotImplementedError instance = gitrepo def islocal(path): if isgitsshuri(path): return True u = util.url(path) return not u.scheme or u.scheme == 'file'