From a8cf575d68e7e211292d967f4a12cf609a028b20 Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Fri, 15 Jul 2022 20:31:33 +0000 Subject: Omit local_manifest groups from superproject override. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we create superproject_override.xml, do not include projects that are present from local_manifests/*. Such projects are fully under the control of the local_manifests/ file. Bug: b/238934278 Test: manual, ./run_tests Change-Id: I40382ceb82d9cf7b8dc7b5f2abed3f6d4d80017e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/340877 Tested-by: Xin Li Reviewed-by: Xin Li Reviewed-by: Sam Saccone 🐐 --- git_superproject.py | 3 ++- manifest_xml.py | 6 +++++- tests/test_git_superproject.py | 3 --- tests/test_manifest_xml.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/git_superproject.py b/git_superproject.py index 5d00bd72..8b6bbcf9 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -295,7 +295,8 @@ class Superproject(object): if not os.path.exists(self._superproject_path): self._LogWarning(f'missing superproject directory: {self._superproject_path}') return None - manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml() + manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr(), + omit_local=True).toxml() manifest_path = self._manifest_path try: with open(manifest_path, 'w', encoding='utf-8') as fp: diff --git a/manifest_xml.py b/manifest_xml.py index 32f6b687..12614c64 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -502,7 +502,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md """ return [x for x in re.split(r'[,\s]+', field) if x] - def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None): + def ToXml(self, peg_rev=False, peg_rev_upstream=True, + peg_rev_dest_branch=True, groups=None, omit_local=False): """Return the current manifest XML.""" mp = self.manifestProject @@ -583,6 +584,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if not p.MatchesGroups(groups): return + if omit_local and self.IsFromLocalManifest(p): + return + name = p.name relpath = p.relpath if parent: diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index 603694d2..0ad9b01d 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py @@ -312,9 +312,6 @@ class SuperprojectTestCase(unittest.TestCase): '' - '' '' '') diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 85c20733..48403c0d 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -252,6 +252,37 @@ class XmlManifestTests(ManifestParseTestCase): '') self.assertEqual(manifest.ToDict(), {}) + def test_toxml_omit_local(self): + """Does not include local_manifests projects when omit_local=True.""" + manifest = self.getXmlManifest( + '' + '' + '' + '' + '' + '') + self.assertEqual( + manifest.ToXml(omit_local=True).toxml(), + '' + '' + '') + + def test_toxml_with_local(self): + """Does include local_manifests projects when omit_local=False.""" + manifest = self.getXmlManifest( + '' + '' + '' + '' + '' + '') + self.assertEqual( + manifest.ToXml(omit_local=False).toxml(), + '' + '' + '' + '') + def test_repo_hooks(self): """Check repo-hooks settings.""" manifest = self.getXmlManifest(""" -- cgit v1.2.3-54-g00ecf