Skip to content

Commit

Permalink
manifest: allow extend-project to override dest-branch and upstream
Browse files Browse the repository at this point in the history
Bug: https://crbug.com/gerrit/16238
Change-Id: Id6eff34791525b3df690e160c911c0286331984b
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/345144
Tested-by: Erik Elmeke <[email protected]>
Reviewed-by: Mike Frysinger <[email protected]>
  • Loading branch information
Erik Elmeke committed Sep 20, 2022
1 parent 1eddca8 commit 4cdfdb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/manifest-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ following DTD:
<!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>
Expand Down Expand Up @@ -423,6 +425,12 @@ project. Same syntax as the corresponding element of `project`.
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
Expand Down
6 changes: 6 additions & 0 deletions manifest_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,8 @@ def recursively_add_projects(project):
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:
Expand All @@ -1304,6 +1306,10 @@ def recursively_add_projects(project):

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]
Expand Down
24 changes: 24 additions & 0 deletions tests/test_manifest_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,27 @@ def test_extend_project_dest_path_multi_match_path_specified(self):
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')

0 comments on commit 4cdfdb7

Please sign in to comment.