Use --negotiation-tip in superproject fetches.

Bug: b/260645739
Change-Id: Ib0cdbb13f130b91ab14df9c60a510f1e27cca8e0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/354354
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Joanna Wang <jojwang@google.com>
This commit is contained in:
Joanna Wang
2022-12-08 17:46:28 -05:00
parent e815286492
commit 0e4f1e7fba
2 changed files with 50 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import tempfile
import unittest
from unittest import mock
from git_command import GitCommand
import git_superproject
import git_trace2_event_log
import manifest_xml
@@ -364,3 +365,41 @@ class SuperprojectTestCase(unittest.TestCase):
'revision="52d3c9f7c107839ece2319d077de0cd922aa9d8f"/>'
'<superproject name="superproject"/>'
'</manifest>')
def test_Fetch(self):
manifest = self.getXmlManifest("""
<manifest>
<remote name="default-remote" fetch="http://localhost" />
<default remote="default-remote" revision="refs/heads/main" />
<superproject name="superproject"/>
" /></manifest>
""")
self.maxDiff = None
self._superproject = git_superproject.Superproject(
manifest, name='superproject',
remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'),
revision='refs/heads/main')
os.mkdir(self._superproject._superproject_path)
os.mkdir(self._superproject._work_git)
with mock.patch.object(self._superproject, '_Init', return_value=True):
with mock.patch('git_superproject.GitCommand', autospec=True) as mock_git_command:
with mock.patch('git_superproject.GitRefs.get', autospec=True) as mock_git_refs:
instance = mock_git_command.return_value
instance.Wait.return_value = 0
mock_git_refs.side_effect = ['', '1234']
self.assertTrue(self._superproject._Fetch())
self.assertEqual(mock_git_command.call_args.args,(None, [
'fetch', 'http://localhost/superproject', '--depth', '1',
'--force', '--no-tags', '--filter', 'blob:none',
'refs/heads/main:refs/heads/main'
]))
# If branch for revision exists, set as --negotiation-tip.
self.assertTrue(self._superproject._Fetch())
self.assertEqual(mock_git_command.call_args.args,(None, [
'fetch', 'http://localhost/superproject', '--depth', '1',
'--force', '--no-tags', '--filter', 'blob:none',
'--negotiation-tip', '1234',
'refs/heads/main:refs/heads/main'
]))