diff options
author | LaMont Jones <lamontjones@google.com> | 2022-07-15 20:31:33 +0000 |
---|---|---|
committer | LaMont Jones <lamontjones@google.com> | 2022-07-15 23:32:24 +0000 |
commit | a8cf575d68e7e211292d967f4a12cf609a028b20 (patch) | |
tree | 8aa89d12dde6b24228187bf71bdadaa97f59af49 | |
parent | 8501d4602a4c85f1e22c7a51ad191af8166efecd (diff) | |
download | git-repo-a8cf575d68e7e211292d967f4a12cf609a028b20.tar.gz |
Omit local_manifest groups from superproject override.v2.28
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 <delphij@google.com>
Reviewed-by: Xin Li <delphij@google.com>
Reviewed-by: Sam Saccone 🐐 <samccone@google.com>
-rw-r--r-- | git_superproject.py | 3 | ||||
-rw-r--r-- | manifest_xml.py | 6 | ||||
-rw-r--r-- | tests/test_git_superproject.py | 3 | ||||
-rw-r--r-- | 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): | |||
295 | if not os.path.exists(self._superproject_path): | 295 | if not os.path.exists(self._superproject_path): |
296 | self._LogWarning(f'missing superproject directory: {self._superproject_path}') | 296 | self._LogWarning(f'missing superproject directory: {self._superproject_path}') |
297 | return None | 297 | return None |
298 | manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml() | 298 | manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr(), |
299 | omit_local=True).toxml() | ||
299 | manifest_path = self._manifest_path | 300 | manifest_path = self._manifest_path |
300 | try: | 301 | try: |
301 | with open(manifest_path, 'w', encoding='utf-8') as fp: | 302 | 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 | |||
502 | """ | 502 | """ |
503 | return [x for x in re.split(r'[,\s]+', field) if x] | 503 | return [x for x in re.split(r'[,\s]+', field) if x] |
504 | 504 | ||
505 | def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None): | 505 | def ToXml(self, peg_rev=False, peg_rev_upstream=True, |
506 | peg_rev_dest_branch=True, groups=None, omit_local=False): | ||
506 | """Return the current manifest XML.""" | 507 | """Return the current manifest XML.""" |
507 | mp = self.manifestProject | 508 | mp = self.manifestProject |
508 | 509 | ||
@@ -583,6 +584,9 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
583 | if not p.MatchesGroups(groups): | 584 | if not p.MatchesGroups(groups): |
584 | return | 585 | return |
585 | 586 | ||
587 | if omit_local and self.IsFromLocalManifest(p): | ||
588 | return | ||
589 | |||
586 | name = p.name | 590 | name = p.name |
587 | relpath = p.relpath | 591 | relpath = p.relpath |
588 | if parent: | 592 | 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): | |||
312 | '<project groups="notdefault,platform-' + self.platform + '" ' | 312 | '<project groups="notdefault,platform-' + self.platform + '" ' |
313 | 'name="platform/art" path="art" ' | 313 | 'name="platform/art" path="art" ' |
314 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' | 314 | 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" upstream="refs/heads/main"/>' |
315 | '<project clone-depth="1" groups="' + local_group + '" ' | ||
316 | 'name="platform/vendor/x" path="vendor/x" remote="goog" ' | ||
317 | 'revision="master-with-vendor"/>' | ||
318 | '<superproject name="superproject"/>' | 315 | '<superproject name="superproject"/>' |
319 | '</manifest>') | 316 | '</manifest>') |
320 | 317 | ||
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): | |||
252 | '<manifest></manifest>') | 252 | '<manifest></manifest>') |
253 | self.assertEqual(manifest.ToDict(), {}) | 253 | self.assertEqual(manifest.ToDict(), {}) |
254 | 254 | ||
255 | def test_toxml_omit_local(self): | ||
256 | """Does not include local_manifests projects when omit_local=True.""" | ||
257 | manifest = self.getXmlManifest( | ||
258 | '<?xml version="1.0" encoding="UTF-8"?><manifest>' | ||
259 | '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' | ||
260 | '<project name="p" groups="local::me"/>' | ||
261 | '<project name="q"/>' | ||
262 | '<project name="r" groups="keep"/>' | ||
263 | '</manifest>') | ||
264 | self.assertEqual( | ||
265 | manifest.ToXml(omit_local=True).toxml(), | ||
266 | '<?xml version="1.0" ?><manifest>' | ||
267 | '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' | ||
268 | '<project name="q"/><project name="r" groups="keep"/></manifest>') | ||
269 | |||
270 | def test_toxml_with_local(self): | ||
271 | """Does include local_manifests projects when omit_local=False.""" | ||
272 | manifest = self.getXmlManifest( | ||
273 | '<?xml version="1.0" encoding="UTF-8"?><manifest>' | ||
274 | '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' | ||
275 | '<project name="p" groups="local::me"/>' | ||
276 | '<project name="q"/>' | ||
277 | '<project name="r" groups="keep"/>' | ||
278 | '</manifest>') | ||
279 | self.assertEqual( | ||
280 | manifest.ToXml(omit_local=False).toxml(), | ||
281 | '<?xml version="1.0" ?><manifest>' | ||
282 | '<remote name="a" fetch=".."/><default remote="a" revision="r"/>' | ||
283 | '<project name="p" groups="local::me"/>' | ||
284 | '<project name="q"/><project name="r" groups="keep"/></manifest>') | ||
285 | |||
255 | def test_repo_hooks(self): | 286 | def test_repo_hooks(self): |
256 | """Check repo-hooks settings.""" | 287 | """Check repo-hooks settings.""" |
257 | manifest = self.getXmlManifest(""" | 288 | manifest = self.getXmlManifest(""" |