diff options
author | Fredrik de Groot <fredrik.de.groot@haleytek.com> | 2024-09-09 15:54:57 +0200 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-10-28 16:55:10 +0000 |
commit | 303bd963d57936873f62c7b61a885911afc46788 (patch) | |
tree | 6970ea441a7873ca08fd5af366a0bd0ba6b7a5ca /tests/test_manifest_xml.py | |
parent | ae384f8623aeb36809541a5e07900a77a0960d5f (diff) | |
download | git-repo-303bd963d57936873f62c7b61a885911afc46788.tar.gz |
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>
Diffstat (limited to 'tests/test_manifest_xml.py')
-rw-r--r-- | tests/test_manifest_xml.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 3f03272a..3d1fde96 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
@@ -1049,6 +1049,91 @@ class RemoveProjectElementTests(ManifestParseTestCase): | |||
1049 | self.assertTrue(found_proj1_path1) | 1049 | self.assertTrue(found_proj1_path1) |
1050 | self.assertTrue(found_proj2) | 1050 | self.assertTrue(found_proj2) |
1051 | 1051 | ||
1052 | def test_base_revision_checks_on_patching(self): | ||
1053 | manifest_fail_wrong_tag = self.getXmlManifest( | ||
1054 | """ | ||
1055 | <manifest> | ||
1056 | <remote name="default-remote" fetch="http://localhost" /> | ||
1057 | <default remote="default-remote" revision="tag.002" /> | ||
1058 | <project name="project1" path="tests/path1" /> | ||
1059 | <extend-project name="project1" revision="new_hash" base-rev="tag.001" /> | ||
1060 | </manifest> | ||
1061 | """ | ||
1062 | ) | ||
1063 | with self.assertRaises(error.ManifestParseError): | ||
1064 | manifest_fail_wrong_tag.ToXml() | ||
1065 | |||
1066 | manifest_fail_remove = self.getXmlManifest( | ||
1067 | """ | ||
1068 | <manifest> | ||
1069 | <remote name="default-remote" fetch="http://localhost" /> | ||
1070 | <default remote="default-remote" revision="refs/heads/main" /> | ||
1071 | <project name="project1" path="tests/path1" revision="hash1" /> | ||
1072 | <remove-project name="project1" base-rev="wrong_hash" /> | ||
1073 | </manifest> | ||
1074 | """ | ||
1075 | ) | ||
1076 | with self.assertRaises(error.ManifestParseError): | ||
1077 | manifest_fail_remove.ToXml() | ||
1078 | |||
1079 | manifest_fail_extend = self.getXmlManifest( | ||
1080 | """ | ||
1081 | <manifest> | ||
1082 | <remote name="default-remote" fetch="http://localhost" /> | ||
1083 | <default remote="default-remote" revision="refs/heads/main" /> | ||
1084 | <project name="project1" path="tests/path1" revision="hash1" /> | ||
1085 | <extend-project name="project1" revision="new_hash" base-rev="wrong_hash" /> | ||
1086 | </manifest> | ||
1087 | """ | ||
1088 | ) | ||
1089 | with self.assertRaises(error.ManifestParseError): | ||
1090 | manifest_fail_extend.ToXml() | ||
1091 | |||
1092 | manifest_fail_unknown = self.getXmlManifest( | ||
1093 | """ | ||
1094 | <manifest> | ||
1095 | <remote name="default-remote" fetch="http://localhost" /> | ||
1096 | <default remote="default-remote" revision="refs/heads/main" /> | ||
1097 | <project name="project1" path="tests/path1" /> | ||
1098 | <extend-project name="project1" revision="new_hash" base-rev="any_hash" /> | ||
1099 | </manifest> | ||
1100 | """ | ||
1101 | ) | ||
1102 | with self.assertRaises(error.ManifestParseError): | ||
1103 | manifest_fail_unknown.ToXml() | ||
1104 | |||
1105 | manifest_ok = self.getXmlManifest( | ||
1106 | """ | ||
1107 | <manifest> | ||
1108 | <remote name="default-remote" fetch="http://localhost" /> | ||
1109 | <default remote="default-remote" revision="refs/heads/main" /> | ||
1110 | <project name="project1" path="tests/path1" revision="hash1" /> | ||
1111 | <project name="project2" path="tests/path2" revision="hash2" /> | ||
1112 | <project name="project3" path="tests/path3" revision="hash3" /> | ||
1113 | <project name="project4" path="tests/path4" revision="hash4" /> | ||
1114 | |||
1115 | <remove-project name="project1" /> | ||
1116 | <remove-project name="project2" base-rev="hash2" /> | ||
1117 | <project name="project2" path="tests/path2" revision="new_hash2" /> | ||
1118 | <extend-project name="project3" base-rev="hash3" revision="new_hash3" /> | ||
1119 | <extend-project name="project3" base-rev="new_hash3" revision="newer_hash3" /> | ||
1120 | <remove-project path="tests/path4" base-rev="hash4" /> | ||
1121 | </manifest> | ||
1122 | """ | ||
1123 | ) | ||
1124 | found_proj2 = False | ||
1125 | found_proj3 = False | ||
1126 | for proj in manifest_ok.projects: | ||
1127 | if proj.name == "project2": | ||
1128 | found_proj2 = True | ||
1129 | if proj.name == "project3": | ||
1130 | found_proj3 = True | ||
1131 | self.assertNotEqual(proj.name, "project1") | ||
1132 | self.assertNotEqual(proj.name, "project4") | ||
1133 | self.assertTrue(found_proj2) | ||
1134 | self.assertTrue(found_proj3) | ||
1135 | self.assertTrue(len(manifest_ok.projects) == 2) | ||
1136 | |||
1052 | 1137 | ||
1053 | class ExtendProjectElementTests(ManifestParseTestCase): | 1138 | class ExtendProjectElementTests(ManifestParseTestCase): |
1054 | """Tests for <extend-project>.""" | 1139 | """Tests for <extend-project>.""" |