summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--git_superproject.py12
-rw-r--r--tests/test_git_superproject.py39
2 files changed, 50 insertions, 1 deletions
diff --git a/git_superproject.py b/git_superproject.py
index 8b6bbcf9..7a4ca16b 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -31,7 +31,7 @@ from typing import NamedTuple
31 31
32from git_command import git_require, GitCommand 32from git_command import git_require, GitCommand
33from git_config import RepoConfig 33from git_config import RepoConfig
34from git_refs import R_HEADS 34from git_refs import R_HEADS, GitRefs
35 35
36_SUPERPROJECT_GIT_NAME = 'superproject.git' 36_SUPERPROJECT_GIT_NAME = 'superproject.git'
37_SUPERPROJECT_MANIFEST_NAME = 'superproject_override.xml' 37_SUPERPROJECT_MANIFEST_NAME = 'superproject_override.xml'
@@ -181,6 +181,16 @@ class Superproject(object):
181 return False 181 return False
182 cmd = ['fetch', self._remote_url, '--depth', '1', '--force', '--no-tags', 182 cmd = ['fetch', self._remote_url, '--depth', '1', '--force', '--no-tags',
183 '--filter', 'blob:none'] 183 '--filter', 'blob:none']
184
185 # Check if there is a local ref that we can pass to --negotiation-tip.
186 # If this is the first fetch, it does not exist yet.
187 # We use --negotiation-tip to speed up the fetch. Superproject branches do
188 # not share commits. So this lets git know it only needs to send commits
189 # reachable from the specified local refs.
190 rev_commit = GitRefs(self._work_git).get(f'refs/heads/{self.revision}')
191 if rev_commit:
192 cmd.extend(['--negotiation-tip', rev_commit])
193
184 if self._branch: 194 if self._branch:
185 cmd += [self._branch + ':' + self._branch] 195 cmd += [self._branch + ':' + self._branch]
186 p = GitCommand(None, 196 p = GitCommand(None,
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
index 225e98c2..49295d83 100644
--- a/tests/test_git_superproject.py
+++ b/tests/test_git_superproject.py
@@ -21,6 +21,7 @@ import tempfile
21import unittest 21import unittest
22from unittest import mock 22from unittest import mock
23 23
24from git_command import GitCommand
24import git_superproject 25import git_superproject
25import git_trace2_event_log 26import git_trace2_event_log
26import manifest_xml 27import manifest_xml
@@ -364,3 +365,41 @@ class SuperprojectTestCase(unittest.TestCase):
364 'revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f"/>' 365 'revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f"/>'
365 '<superproject name="superproject"/>' 366 '<superproject name="superproject"/>'
366 '</manifest>') 367 '</manifest>')
368
369 def test_Fetch(self):
370 manifest = self.getXmlManifest("""
371<manifest>
372 <remote name="default-remote" fetch="http://localhost" />
373 <default remote="default-remote" revision="refs/heads/main" />
374 <superproject name="superproject"/>
375 " /></manifest>
376""")
377 self.maxDiff = None
378 self._superproject = git_superproject.Superproject(
379 manifest, name='superproject',
380 remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'),
381 revision='refs/heads/main')
382 os.mkdir(self._superproject._superproject_path)
383 os.mkdir(self._superproject._work_git)
384 with mock.patch.object(self._superproject, '_Init', return_value=True):
385 with mock.patch('git_superproject.GitCommand', autospec=True) as mock_git_command:
386 with mock.patch('git_superproject.GitRefs.get', autospec=True) as mock_git_refs:
387 instance = mock_git_command.return_value
388 instance.Wait.return_value = 0
389 mock_git_refs.side_effect = ['', '1234']
390
391 self.assertTrue(self._superproject._Fetch())
392 self.assertEqual(mock_git_command.call_args.args,(None, [
393 'fetch', 'http://localhost/superproject', '--depth', '1',
394 '--force', '--no-tags', '--filter', 'blob:none',
395 'refs/heads/main:refs/heads/main'
396 ]))
397
398 # If branch for revision exists, set as --negotiation-tip.
399 self.assertTrue(self._superproject._Fetch())
400 self.assertEqual(mock_git_command.call_args.args,(None, [
401 'fetch', 'http://localhost/superproject', '--depth', '1',
402 '--force', '--no-tags', '--filter', 'blob:none',
403 '--negotiation-tip', '1234',
404 'refs/heads/main:refs/heads/main'
405 ]))