diff --git a/git_superproject.py b/git_superproject.py index 5d00bd72fa8d32a50094128a9f3e9216e23dc3b2..8b6bbcf9aa36d47a62f31eebd04a4826d090c088 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 32f6b6878be22a496e15e04d9c77febc0b28583e..12614c64a99efeea775197f6266b3b9a9e5271e3 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 603694d2d0a9d51fd828cf4aea4670de543f00bf..0ad9b01ded15ddabf86b5ea97b774868eb43953d 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py @@ -312,9 +312,6 @@ class SuperprojectTestCase(unittest.TestCase): '<project groups="notdefault,platform-' + self.platform + '" ' 'name="platform/art" path="art" ' 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' - '<project clone-depth="1" groups="' + local_group + '" ' - 'name="platform/vendor/x" path="vendor/x" remote="goog" ' - 'revision="master-with-vendor"/>' '<superproject name="superproject"/>' '</manifest>') diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 85c20733ca8bc41c7a3b2395bbb6980c13888bf3..48403c0da7f7a187bdced091089af00181a34703 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -252,6 +252,37 @@ class XmlManifestTests(ManifestParseTestCase): '<manifest></manifest>') self.assertEqual(manifest.ToDict(), {}) + def test_toxml_omit_local(self): + """Does not include local_manifests projects when omit_local=True.""" + manifest = self.getXmlManifest( + '<?xml version="1.0" encoding="UTF-8"?><manifest>' + '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' + '<project name="p" groups="local::me"/>' + '<project name="q"/>' + '<project name="r" groups="keep"/>' + '</manifest>') + self.assertEqual( + manifest.ToXml(omit_local=True).toxml(), + '<?xml version="1.0" ?><manifest>' + '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' + '<project name="q"/><project name="r" groups="keep"/></manifest>') + + def test_toxml_with_local(self): + """Does include local_manifests projects when omit_local=False.""" + manifest = self.getXmlManifest( + '<?xml version="1.0" encoding="UTF-8"?><manifest>' + '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' + '<project name="p" groups="local::me"/>' + '<project name="q"/>' + '<project name="r" groups="keep"/>' + '</manifest>') + self.assertEqual( + manifest.ToXml(omit_local=False).toxml(), + '<?xml version="1.0" ?><manifest>' + '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' + '<project name="p" groups="local::me"/>' + '<project name="q"/><project name="r" groups="keep"/></manifest>') + def test_repo_hooks(self): """Check repo-hooks settings.""" manifest = self.getXmlManifest("""