diff --git a/repo_resource/common.py b/repo_resource/common.py
index 3649bce..aa3cfd1 100644
--- a/repo_resource/common.py
+++ b/repo_resource/common.py
@@ -355,6 +355,7 @@ def __manifest_out(self, filename):
def update_manifest(self, jobs):
projects = []
+ removed_projects = []
jobs = jobs or DEFAULT_CHECK_JOBS
self.__change_to_workdir()
@@ -379,6 +380,24 @@ def update_manifest(self, jobs):
defaultBranch = defaults.get('revision') \
or self.__get_remote_revision(defaultRemote)
+ # Handle element:
+ # - Should not be present in final XML (for version)
+ # - Should remove first matching project by name
+ for p in manifest.findall('remove-project'):
+ project = p.get('name')
+ removed_projects.append(project)
+ manifest.remove(p)
+
+ for p in manifest.findall('project'):
+ project = p.get('name')
+ if project in removed_projects:
+ manifest.remove(p)
+ removed_projects.remove(project)
+ # If there are no more projects to remove, we can
+ # skip parsing the rest of the projects
+ if not removed_projects:
+ break
+
for p in manifest.findall('project'):
project = p.get('name')
projectBranch = p.get('revision') or defaultBranch
diff --git a/repo_resource/test_check.py b/repo_resource/test_check.py
index 706c6fd..04e0284 100644
--- a/repo_resource/test_check.py
+++ b/repo_resource/test_check.py
@@ -59,6 +59,13 @@ def setUp(self):
'name': 'aosp_multiple_device_fixed.xml'
}
}
+ self.remove_project_source = {
+ 'source': {
+ 'url': 'https://github.com/makohoek/demo-manifests.git',
+ 'revision': 'main',
+ 'name': 'aosp_remove_yukawa_project.xml'
+ }
+ }
def tearDown(self):
p = common.CACHEDIR
@@ -359,6 +366,26 @@ def test_jobs_limit(self):
print('fast: {} slow: {}'.format(fast_duration, slow_duration))
self.assertTrue(fast_duration < slow_duration)
+ # test that the `` tag is correctly handled
+ # When rebuilding the Version string.
+ # See: https://github.com/makohoek/repo-resource/issues/36
+ def test_remove_project_version(self):
+ data = self.remove_project_source
+ instream = StringIO(json.dumps(data))
+ versions = check.check(instream)
+
+ expected_version = '' # noqa: E501
+
+ version = versions[0]['version']
+ self.assertEqual(version, expected_version)
+
+ def test_no_remove_project_element(self):
+ data = self.remove_project_source
+ instream = StringIO(json.dumps(data))
+ versions = check.check(instream)
+ version = versions[0]['version']
+ self.assertNotIn('remove-project', version)
+
if __name__ == '__main__':
unittest.main()