def pull(self, wire, url, apply_refs=True, refs=None, update_after=False): if url != 'default' and '://' not in url: client = LocalGitClient(url) else: url_obj = url_parser(url) o = self._build_opener(url) url, _ = url_obj.authinfo() client = HttpGitClient(base_url=url, opener=o) repo = self._factory.repo(wire) determine_wants = repo.object_store.determine_wants_all if refs: def determine_wants_requested(references): return [references[r] for r in references if r in refs] determine_wants = determine_wants_requested try: remote_refs = client.fetch(path=url, target=repo, determine_wants=determine_wants) except NotGitRepository as e: log.warning( 'Trying to fetch from "%s" failed, not a Git repository.', url) # Exception can contain unicode which we convert raise exceptions.AbortException(e)(repr(e)) # mikhail: client.fetch() returns all the remote refs, but fetches only # refs filtered by `determine_wants` function. We need to filter result # as well if refs: remote_refs = {k: remote_refs[k] for k in remote_refs if k in refs} if apply_refs: # TODO: johbo: Needs proper test coverage with a git repository # that contains a tag object, so that we would end up with # a peeled ref at this point. for k in remote_refs: if k.endswith(PEELED_REF_MARKER): log.debug("Skipping peeled reference %s", k) continue repo[k] = remote_refs[k] if refs and not update_after: # mikhail: explicitly set the head to the last ref. repo['HEAD'] = remote_refs[refs[-1]] if update_after: # we want to checkout HEAD repo["HEAD"] = remote_refs["HEAD"] index.build_index_from_tree(repo.path, repo.index_path(), repo.object_store, repo["HEAD"].tree) return remote_refs
def fetch(self, wire, url, apply_refs=True, refs=None): if url != 'default' and '://' not in url: client = LocalGitClient(url) else: url_obj = hg_url(url) o = self._build_opener(url) url, _ = url_obj.authinfo() client = HttpGitClient(base_url=url, opener=o) repo = self._factory.repo(wire) determine_wants = repo.object_store.determine_wants_all if refs: def determine_wants_requested(references): return [references[r] for r in references if r in refs] determine_wants = determine_wants_requested try: remote_refs = client.fetch(path=url, target=repo, determine_wants=determine_wants) except NotGitRepository: log.warning( 'Trying to fetch from "%s" failed, not a Git repository.', url) raise exceptions.AbortException() # mikhail: client.fetch() returns all the remote refs, but fetches only # refs filtered by `determine_wants` function. We need to filter result # as well if refs: remote_refs = {k: remote_refs[k] for k in remote_refs if k in refs} if apply_refs: # TODO: johbo: Needs proper test coverage with a git repository # that contains a tag object, so that we would end up with # a peeled ref at this point. PEELED_REF_MARKER = '^{}' for k in remote_refs: if k.endswith(PEELED_REF_MARKER): log.info("Skipping peeled reference %s", k) continue repo[k] = remote_refs[k] if refs: # mikhail: explicitly set the head to the last ref. repo['HEAD'] = remote_refs[refs[-1]] # TODO: mikhail: should we return remote_refs here to be # consistent? else: return remote_refs
def fetch(self, wire, url, apply_refs=True, refs=None): if url != 'default' and '://' not in url: client = LocalGitClient(url) else: url_obj = hg_url(url) o = self._build_opener(url) url, _ = url_obj.authinfo() client = HttpGitClient(base_url=url, opener=o) repo = self._factory.repo(wire) determine_wants = repo.object_store.determine_wants_all if refs: def determine_wants_requested(references): return [references[r] for r in references if r in refs] determine_wants = determine_wants_requested try: remote_refs = client.fetch( path=url, target=repo, determine_wants=determine_wants) except NotGitRepository: log.warning( 'Trying to fetch from "%s" failed, not a Git repository.', url) raise exceptions.AbortException() # mikhail: client.fetch() returns all the remote refs, but fetches only # refs filtered by `determine_wants` function. We need to filter result # as well if refs: remote_refs = {k: remote_refs[k] for k in remote_refs if k in refs} if apply_refs: # TODO: johbo: Needs proper test coverage with a git repository # that contains a tag object, so that we would end up with # a peeled ref at this point. PEELED_REF_MARKER = '^{}' for k in remote_refs: if k.endswith(PEELED_REF_MARKER): log.info("Skipping peeled reference %s", k) continue repo[k] = remote_refs[k] if refs: # mikhail: explicitly set the head to the last ref. repo['HEAD'] = remote_refs[refs[-1]] # TODO: mikhail: should we return remote_refs here to be # consistent? else: return remote_refs
def test_fetch_into_empty(self): c = LocalGitClient() t = MemoryRepo() s = open_repo('a.git') self.addCleanup(tear_down_repo, s) self.assertEqual(s.get_refs(), c.fetch(s.path, t))
def test_fetch_into_empty(self): c = LocalGitClient() t = MemoryRepo() s = open_repo('a.git') self.assertEquals(s.get_refs(), c.fetch(s.path, t))
def test_fetch_into_empty(self): c = LocalGitClient() t = MemoryRepo() s = open_repo('a.git') self.addCleanup(tear_down_repo, s) self.assertEqual(s.get_refs(), c.fetch(s.path, t).refs)