manifest: allow extend-project to override dest-branch and upstream
Bug: https://crbug.com/gerrit/16238
Change-Id: Id6eff34791525b3df690e160c911c0286331984b
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/345144
Tested-by: Erik Elmeke <erik@haleytek.corp-partner.google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
diff --git a/docs/manifest-format.md b/docs/manifest-format.md
index 0d26296..bcdf5a8 100644
--- a/docs/manifest-format.md
+++ b/docs/manifest-format.md
@@ -105,6 +105,8 @@
<!ATTLIST extend-project groups CDATA #IMPLIED>
<!ATTLIST extend-project revision CDATA #IMPLIED>
<!ATTLIST extend-project remote CDATA #IMPLIED>
+ <!ATTLIST extend-project dest-branch CDATA #IMPLIED>
+ <!ATTLIST extend-project upstream CDATA #IMPLIED>
<!ELEMENT remove-project EMPTY>
<!ATTLIST remove-project name CDATA #REQUIRED>
@@ -423,6 +425,12 @@
Attribute `remote`: If specified, overrides the remote of the original
project. Same syntax as the corresponding element of `project`.
+Attribute `dest-branch`: If specified, overrides the dest-branch of the original
+project. Same syntax as the corresponding element of `project`.
+
+Attribute `upstream`: If specified, overrides the upstream of the original
+project. Same syntax as the corresponding element of `project`.
+
### Element annotation
Zero or more annotation elements may be specified as children of a
diff --git a/manifest_xml.py b/manifest_xml.py
index b7579d5..129eb3f 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -1289,6 +1289,8 @@
remote = self._default.remote
else:
remote = self._get_remote(node)
+ dest_branch = node.getAttribute('dest-branch')
+ upstream = node.getAttribute('upstream')
named_projects = self._projects[name]
if dest_path and not path and len(named_projects) > 1:
@@ -1304,6 +1306,10 @@
if remote_name:
p.remote = remote.ToRemoteSpec(name)
+ if dest_branch:
+ p.dest_branch = dest_branch
+ if upstream:
+ p.upstream = upstream
if dest_path:
del self._paths[p.relpath]
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index 48403c0..e181b64 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -874,3 +874,27 @@
else:
self.assertEqual(manifest.projects[0].relpath, 'bar')
self.assertEqual(manifest.projects[1].relpath, 'y')
+
+ def test_extend_project_dest_branch(self):
+ manifest = self.getXmlManifest("""
+<manifest>
+ <remote name="default-remote" fetch="http://localhost" />
+ <default remote="default-remote" revision="refs/heads/main" dest-branch="foo" />
+ <project name="myproject" />
+ <extend-project name="myproject" dest-branch="bar" />
+</manifest>
+""")
+ self.assertEqual(len(manifest.projects), 1)
+ self.assertEqual(manifest.projects[0].dest_branch, 'bar')
+
+ def test_extend_project_upstream(self):
+ manifest = self.getXmlManifest("""
+<manifest>
+ <remote name="default-remote" fetch="http://localhost" />
+ <default remote="default-remote" revision="refs/heads/main" />
+ <project name="myproject" />
+ <extend-project name="myproject" upstream="bar" />
+</manifest>
+""")
+ self.assertEqual(len(manifest.projects), 1)
+ self.assertEqual(manifest.projects[0].upstream, 'bar')