From 0e776a5837d08d58cedd1d9e4288ed7db349749c Mon Sep 17 00:00:00 2001 From: Xin Li Date: Tue, 29 Jun 2021 21:42:34 +0000 Subject: [PATCH] Fix an issue when syncing with --use-superproject and clone bundles. It is possible that a clone bundle contained the object referenced by the branch in the manifest and in the superproject, but not the branch itself (for example, the branch may be newly created from an existing branch, or is not vislble to the user downloading the clone bundle). When --use-superproject is enabled, because we are overriding revisionExpr with the SHA1 revision provided by the superproject, the verification step would succeed, but because the expected branch do not exist, it would confuse git-repo at a later time, as it is expecting the remote branch to exist in the local clone. In project.py, fix this by making SetRevisionId() to always remember the actual branch name and verify it in _CheckForImmutableRevision() so that we only skip the fetch step when both objects exists locally. Bug: [google internal] b/191974277 Change-Id: I49d3ca0667f524c8c45f416492faf95b1dd822fb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/310802 Reviewed-by: Raman Tenneti Reviewed-by: Mike Frysinger Tested-by: Xin Li --- project.py | 6 +++++- tests/test_git_superproject.py | 12 ++++++------ tests/test_manifest_xml.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/project.py b/project.py index 2ab0b389..e777dbd2 100644 --- a/project.py +++ b/project.py @@ -1216,7 +1216,7 @@ class Project(object): (self.revisionExpr, self.name)) def SetRevisionId(self, revisionId): - if self.clone_depth or self.manifest.manifestProject.config.GetString('repo.depth'): + if self.revisionExpr: self.upstream = self.revisionExpr self.revisionId = revisionId @@ -1967,6 +1967,10 @@ class Project(object): # throws an error. self.bare_git.rev_list('-1', '--missing=allow-any', '%s^0' % self.revisionExpr, '--') + if self.upstream: + rev = self.GetRemote(self.remote.name).ToLocal(self.upstream) + self.bare_git.rev_list('-1', '--missing=allow-any', + '%s^0' % rev, '--') return True except GitError: # There is no such persistent revision. We have to fetch it. diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index c3f88531..6ff81843 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py @@ -213,7 +213,7 @@ class SuperprojectTestCase(unittest.TestCase): '' '' '' + 'name="platform/art" path="art" revision="ABCDEF" upstream="refs/heads/main"/>' '' '') @@ -242,7 +242,7 @@ class SuperprojectTestCase(unittest.TestCase): '' '' + 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' '' '') @@ -271,7 +271,7 @@ class SuperprojectTestCase(unittest.TestCase): '' '' '' - '' + '' '') def test_superproject_update_project_revision_id_from_local_manifest_group(self): @@ -316,7 +316,7 @@ class SuperprojectTestCase(unittest.TestCase): '' '' + 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' '' @@ -363,9 +363,9 @@ class SuperprojectTestCase(unittest.TestCase): '' '' + 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' '' + 'revision="e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06" upstream="refs/heads/main"/>' '' '' diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 2a16900a..55468b51 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -437,7 +437,7 @@ class ProjectElementTests(ManifestParseTestCase): '' '' '' - '' + '' '') def test_trailing_slash(self):