mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
manifest: add optional base check on remove and extend
This adds an optional, built-in checker for guarding against patches hanging on wrong base revisions, which is useful if a lower layer of the manifest changes after a patch was done. When adding a patch with a new revision using extend-project or remove-project/project: C---D---E patches in project bla / A---B project bla in manifest state 1 <extend-project name="bla" revision="E" base-rev="B"> If project bla gets updated, in a new snap ID or by a supplier or similar, to a new state: C---D---E patches in project bla / A---B---F---G project bla in manifest state 2 Parsing will fail because revision of bla is now G, giving the choice to create a new patch branch from G and updating base-rev, or keeping previous branch for some reason and only updating base-rev. Intended for use in a layered manifest with hashed revisions. Named refs like branches and tags also work fine when comparing, but will be misleading if a branch is used as base-rev. Change-Id: Ic6211550a7d3cc9656057f6a2087c505b40cad2b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/436777 Reviewed-by: Josip Sokcevic <sokcevic@google.com> Tested-by: Fredrik de Groot <fredrik.de.groot@haleytek.com> Commit-Queue: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
@ -1049,6 +1049,91 @@ class RemoveProjectElementTests(ManifestParseTestCase):
|
||||
self.assertTrue(found_proj1_path1)
|
||||
self.assertTrue(found_proj2)
|
||||
|
||||
def test_base_revision_checks_on_patching(self):
|
||||
manifest_fail_wrong_tag = self.getXmlManifest(
|
||||
"""
|
||||
<manifest>
|
||||
<remote name="default-remote" fetch="http://localhost" />
|
||||
<default remote="default-remote" revision="tag.002" />
|
||||
<project name="project1" path="tests/path1" />
|
||||
<extend-project name="project1" revision="new_hash" base-rev="tag.001" />
|
||||
</manifest>
|
||||
"""
|
||||
)
|
||||
with self.assertRaises(error.ManifestParseError):
|
||||
manifest_fail_wrong_tag.ToXml()
|
||||
|
||||
manifest_fail_remove = self.getXmlManifest(
|
||||
"""
|
||||
<manifest>
|
||||
<remote name="default-remote" fetch="http://localhost" />
|
||||
<default remote="default-remote" revision="refs/heads/main" />
|
||||
<project name="project1" path="tests/path1" revision="hash1" />
|
||||
<remove-project name="project1" base-rev="wrong_hash" />
|
||||
</manifest>
|
||||
"""
|
||||
)
|
||||
with self.assertRaises(error.ManifestParseError):
|
||||
manifest_fail_remove.ToXml()
|
||||
|
||||
manifest_fail_extend = self.getXmlManifest(
|
||||
"""
|
||||
<manifest>
|
||||
<remote name="default-remote" fetch="http://localhost" />
|
||||
<default remote="default-remote" revision="refs/heads/main" />
|
||||
<project name="project1" path="tests/path1" revision="hash1" />
|
||||
<extend-project name="project1" revision="new_hash" base-rev="wrong_hash" />
|
||||
</manifest>
|
||||
"""
|
||||
)
|
||||
with self.assertRaises(error.ManifestParseError):
|
||||
manifest_fail_extend.ToXml()
|
||||
|
||||
manifest_fail_unknown = self.getXmlManifest(
|
||||
"""
|
||||
<manifest>
|
||||
<remote name="default-remote" fetch="http://localhost" />
|
||||
<default remote="default-remote" revision="refs/heads/main" />
|
||||
<project name="project1" path="tests/path1" />
|
||||
<extend-project name="project1" revision="new_hash" base-rev="any_hash" />
|
||||
</manifest>
|
||||
"""
|
||||
)
|
||||
with self.assertRaises(error.ManifestParseError):
|
||||
manifest_fail_unknown.ToXml()
|
||||
|
||||
manifest_ok = self.getXmlManifest(
|
||||
"""
|
||||
<manifest>
|
||||
<remote name="default-remote" fetch="http://localhost" />
|
||||
<default remote="default-remote" revision="refs/heads/main" />
|
||||
<project name="project1" path="tests/path1" revision="hash1" />
|
||||
<project name="project2" path="tests/path2" revision="hash2" />
|
||||
<project name="project3" path="tests/path3" revision="hash3" />
|
||||
<project name="project4" path="tests/path4" revision="hash4" />
|
||||
|
||||
<remove-project name="project1" />
|
||||
<remove-project name="project2" base-rev="hash2" />
|
||||
<project name="project2" path="tests/path2" revision="new_hash2" />
|
||||
<extend-project name="project3" base-rev="hash3" revision="new_hash3" />
|
||||
<extend-project name="project3" base-rev="new_hash3" revision="newer_hash3" />
|
||||
<remove-project path="tests/path4" base-rev="hash4" />
|
||||
</manifest>
|
||||
"""
|
||||
)
|
||||
found_proj2 = False
|
||||
found_proj3 = False
|
||||
for proj in manifest_ok.projects:
|
||||
if proj.name == "project2":
|
||||
found_proj2 = True
|
||||
if proj.name == "project3":
|
||||
found_proj3 = True
|
||||
self.assertNotEqual(proj.name, "project1")
|
||||
self.assertNotEqual(proj.name, "project4")
|
||||
self.assertTrue(found_proj2)
|
||||
self.assertTrue(found_proj3)
|
||||
self.assertTrue(len(manifest_ok.projects) == 2)
|
||||
|
||||
|
||||
class ExtendProjectElementTests(ManifestParseTestCase):
|
||||
"""Tests for <extend-project>."""
|
||||
|
Reference in New Issue
Block a user