Show More
@@ -98,7 +98,7 b' class GitRemote(object):' | |||||
98 |
|
98 | |||
99 | def __init__(self, factory): |
|
99 | def __init__(self, factory): | |
100 | self._factory = factory |
|
100 | self._factory = factory | |
101 |
|
101 | self.peeled_ref_marker = '^{}' | ||
102 | self._bulk_methods = { |
|
102 | self._bulk_methods = { | |
103 | "author": self.commit_attribute, |
|
103 | "author": self.commit_attribute, | |
104 | "date": self.get_object_attrs, |
|
104 | "date": self.get_object_attrs, | |
@@ -279,7 +279,8 b' class GitRemote(object):' | |||||
279 |
|
279 | |||
280 | @reraise_safe_exceptions |
|
280 | @reraise_safe_exceptions | |
281 | def clone(self, wire, url, deferred, valid_refs, update_after_clone): |
|
281 | def clone(self, wire, url, deferred, valid_refs, update_after_clone): | |
282 | remote_refs = self.fetch(wire, url, apply_refs=False) |
|
282 | # TODO(marcink): deprecate this method. Last i checked we don't use it anymore | |
|
283 | remote_refs = self.pull(wire, url, apply_refs=False) | |||
283 | repo = self._factory.repo(wire) |
|
284 | repo = self._factory.repo(wire) | |
284 | if isinstance(valid_refs, list): |
|
285 | if isinstance(valid_refs, list): | |
285 | valid_refs = tuple(valid_refs) |
|
286 | valid_refs = tuple(valid_refs) | |
@@ -396,7 +397,7 b' class GitRemote(object):' | |||||
396 | return commit.id |
|
397 | return commit.id | |
397 |
|
398 | |||
398 | @reraise_safe_exceptions |
|
399 | @reraise_safe_exceptions | |
399 |
def |
|
400 | def pull(self, wire, url, apply_refs=True, refs=None): | |
400 | if url != 'default' and '://' not in url: |
|
401 | if url != 'default' and '://' not in url: | |
401 | client = LocalGitClient(url) |
|
402 | client = LocalGitClient(url) | |
402 | else: |
|
403 | else: | |
@@ -431,10 +432,9 b' class GitRemote(object):' | |||||
431 | # TODO: johbo: Needs proper test coverage with a git repository |
|
432 | # TODO: johbo: Needs proper test coverage with a git repository | |
432 | # that contains a tag object, so that we would end up with |
|
433 | # that contains a tag object, so that we would end up with | |
433 | # a peeled ref at this point. |
|
434 | # a peeled ref at this point. | |
434 | PEELED_REF_MARKER = '^{}' |
|
|||
435 | for k in remote_refs: |
|
435 | for k in remote_refs: | |
436 |
if k.endswith( |
|
436 | if k.endswith(self.peeled_ref_marker): | |
437 |
log. |
|
437 | log.debug("Skipping peeled reference %s", k) | |
438 | continue |
|
438 | continue | |
439 | repo[k] = remote_refs[k] |
|
439 | repo[k] = remote_refs[k] | |
440 |
|
440 | |||
@@ -442,8 +442,6 b' class GitRemote(object):' | |||||
442 | # mikhail: explicitly set the head to the last ref. |
|
442 | # mikhail: explicitly set the head to the last ref. | |
443 | repo['HEAD'] = remote_refs[refs[-1]] |
|
443 | repo['HEAD'] = remote_refs[refs[-1]] | |
444 |
|
444 | |||
445 | # TODO: mikhail: should we return remote_refs here to be |
|
|||
446 | # consistent? |
|
|||
447 | else: |
|
445 | else: | |
448 | return remote_refs |
|
446 | return remote_refs | |
449 |
|
447 | |||
@@ -453,7 +451,7 b' class GitRemote(object):' | |||||
453 | if refs and not isinstance(refs, (list, tuple)): |
|
451 | if refs and not isinstance(refs, (list, tuple)): | |
454 | refs = [refs] |
|
452 | refs = [refs] | |
455 |
|
453 | |||
456 | # get remote heads |
|
454 | # get all remote refs we'll use to fetch later | |
457 | output, __ = self.run_git_command( |
|
455 | output, __ = self.run_git_command( | |
458 | wire, ['ls-remote', url], fail_on_stderr=False, |
|
456 | wire, ['ls-remote', url], fail_on_stderr=False, | |
459 | _copts=['-c', 'core.askpass=""'], |
|
457 | _copts=['-c', 'core.askpass=""'], | |
@@ -461,9 +459,16 b' class GitRemote(object):' | |||||
461 |
|
459 | |||
462 | remote_refs = collections.OrderedDict() |
|
460 | remote_refs = collections.OrderedDict() | |
463 | fetch_refs = [] |
|
461 | fetch_refs = [] | |
|
462 | ||||
464 | for ref_line in output.splitlines(): |
|
463 | for ref_line in output.splitlines(): | |
465 | sha, ref = ref_line.split('\t') |
|
464 | sha, ref = ref_line.split('\t') | |
466 | sha = sha.strip() |
|
465 | sha = sha.strip() | |
|
466 | if ref in remote_refs: | |||
|
467 | # duplicate, skip | |||
|
468 | continue | |||
|
469 | if ref.endswith(self.peeled_ref_marker): | |||
|
470 | log.debug("Skipping peeled reference %s", ref) | |||
|
471 | continue | |||
467 | remote_refs[ref] = sha |
|
472 | remote_refs[ref] = sha | |
468 |
|
473 | |||
469 | if refs and sha in refs: |
|
474 | if refs and sha in refs: | |
@@ -472,10 +477,10 b' class GitRemote(object):' | |||||
472 | elif not refs: |
|
477 | elif not refs: | |
473 | fetch_refs.append('{}:{}'.format(ref, ref)) |
|
478 | fetch_refs.append('{}:{}'.format(ref, ref)) | |
474 |
|
479 | |||
475 | fetch_refs.append('{}:{}'.format(ref, ref)) |
|
480 | if fetch_refs: | |
476 |
|
||||
477 | _out, _err = self.run_git_command( |
|
481 | _out, _err = self.run_git_command( | |
478 |
wire, ['fetch', url, '--'] + fetch_refs, |
|
482 | wire, ['fetch', url, '--prune', '--'] + fetch_refs, | |
|
483 | fail_on_stderr=False, | |||
479 | _copts=['-c', 'core.askpass=""'], |
|
484 | _copts=['-c', 'core.askpass=""'], | |
480 | extra_env={'GIT_TERMINAL_PROMPT': '0'}) |
|
485 | extra_env={'GIT_TERMINAL_PROMPT': '0'}) | |
481 |
|
486 |
@@ -61,7 +61,7 b' class TestGitFetch(object):' | |||||
61 |
|
61 | |||
62 | with patch('dulwich.client.LocalGitClient.fetch') as mock_fetch: |
|
62 | with patch('dulwich.client.LocalGitClient.fetch') as mock_fetch: | |
63 | mock_fetch.side_effect = side_effect |
|
63 | mock_fetch.side_effect = side_effect | |
64 |
self.remote_git. |
|
64 | self.remote_git.pull(wire=None, url='/tmp/', apply_refs=False) | |
65 | determine_wants = self.mock_repo.object_store.determine_wants_all |
|
65 | determine_wants = self.mock_repo.object_store.determine_wants_all | |
66 | determine_wants.assert_called_once_with(SAMPLE_REFS) |
|
66 | determine_wants.assert_called_once_with(SAMPLE_REFS) | |
67 |
|
67 | |||
@@ -78,7 +78,7 b' class TestGitFetch(object):' | |||||
78 |
|
78 | |||
79 | with patch('dulwich.client.LocalGitClient.fetch') as mock_fetch: |
|
79 | with patch('dulwich.client.LocalGitClient.fetch') as mock_fetch: | |
80 | mock_fetch.side_effect = side_effect |
|
80 | mock_fetch.side_effect = side_effect | |
81 |
self.remote_git. |
|
81 | self.remote_git.pull( | |
82 | wire=None, url='/tmp/', apply_refs=False, |
|
82 | wire=None, url='/tmp/', apply_refs=False, | |
83 | refs=selected_refs.keys()) |
|
83 | refs=selected_refs.keys()) | |
84 | determine_wants = self.mock_repo.object_store.determine_wants_all |
|
84 | determine_wants = self.mock_repo.object_store.determine_wants_all |
General Comments 0
You need to be logged in to leave comments.
Login now