diff options
-rw-r--r-- | manifest_xml.py | 49 | ||||
-rw-r--r-- | tests/test_manifest_xml.py | 13 |
2 files changed, 39 insertions, 23 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 55ad6c08..7099d5fe 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -852,6 +852,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
852 | for subproject in project.subprojects: | 852 | for subproject in project.subprojects: |
853 | recursively_add_projects(subproject) | 853 | recursively_add_projects(subproject) |
854 | 854 | ||
855 | repo_hooks_project = None | ||
856 | enabled_repo_hooks = None | ||
855 | for node in itertools.chain(*node_list): | 857 | for node in itertools.chain(*node_list): |
856 | if node.nodeName == 'project': | 858 | if node.nodeName == 'project': |
857 | project = self._ParseProject(node) | 859 | project = self._ParseProject(node) |
@@ -886,32 +888,15 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
886 | if remote: | 888 | if remote: |
887 | p.remote = remote.ToRemoteSpec(name) | 889 | p.remote = remote.ToRemoteSpec(name) |
888 | if node.nodeName == 'repo-hooks': | 890 | if node.nodeName == 'repo-hooks': |
889 | # Get the name of the project and the (space-separated) list of enabled. | ||
890 | repo_hooks_project = self._reqatt(node, 'in-project') | ||
891 | enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) | ||
892 | |||
893 | # Only one project can be the hooks project | 891 | # Only one project can be the hooks project |
894 | if self._repo_hooks_project is not None: | 892 | if repo_hooks_project is not None: |
895 | raise ManifestParseError( | 893 | raise ManifestParseError( |
896 | 'duplicate repo-hooks in %s' % | 894 | 'duplicate repo-hooks in %s' % |
897 | (self.manifestFile)) | 895 | (self.manifestFile)) |
898 | 896 | ||
899 | # Store a reference to the Project. | 897 | # Get the name of the project and the (space-separated) list of enabled. |
900 | try: | 898 | repo_hooks_project = self._reqatt(node, 'in-project') |
901 | repo_hooks_projects = self._projects[repo_hooks_project] | 899 | enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) |
902 | except KeyError: | ||
903 | raise ManifestParseError( | ||
904 | 'project %s not found for repo-hooks' % | ||
905 | (repo_hooks_project)) | ||
906 | |||
907 | if len(repo_hooks_projects) != 1: | ||
908 | raise ManifestParseError( | ||
909 | 'internal error parsing repo-hooks in %s' % | ||
910 | (self.manifestFile)) | ||
911 | self._repo_hooks_project = repo_hooks_projects[0] | ||
912 | |||
913 | # Store the enabled hooks in the Project object. | ||
914 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks | ||
915 | if node.nodeName == 'superproject': | 900 | if node.nodeName == 'superproject': |
916 | name = self._reqatt(node, 'name') | 901 | name = self._reqatt(node, 'name') |
917 | # There can only be one superproject. | 902 | # There can only be one superproject. |
@@ -944,12 +929,30 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
944 | 929 | ||
945 | # If the manifest removes the hooks project, treat it as if it deleted | 930 | # If the manifest removes the hooks project, treat it as if it deleted |
946 | # the repo-hooks element too. | 931 | # the repo-hooks element too. |
947 | if self._repo_hooks_project and (self._repo_hooks_project.name == name): | 932 | if repo_hooks_project == name: |
948 | self._repo_hooks_project = None | 933 | repo_hooks_project = None |
949 | elif not XmlBool(node, 'optional', False): | 934 | elif not XmlBool(node, 'optional', False): |
950 | raise ManifestParseError('remove-project element specifies non-existent ' | 935 | raise ManifestParseError('remove-project element specifies non-existent ' |
951 | 'project: %s' % name) | 936 | 'project: %s' % name) |
952 | 937 | ||
938 | # Store repo hooks project information. | ||
939 | if repo_hooks_project: | ||
940 | # Store a reference to the Project. | ||
941 | try: | ||
942 | repo_hooks_projects = self._projects[repo_hooks_project] | ||
943 | except KeyError: | ||
944 | raise ManifestParseError( | ||
945 | 'project %s not found for repo-hooks' % | ||
946 | (repo_hooks_project)) | ||
947 | |||
948 | if len(repo_hooks_projects) != 1: | ||
949 | raise ManifestParseError( | ||
950 | 'internal error parsing repo-hooks in %s' % | ||
951 | (self.manifestFile)) | ||
952 | self._repo_hooks_project = repo_hooks_projects[0] | ||
953 | # Store the enabled hooks in the Project object. | ||
954 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks | ||
955 | |||
953 | def _AddMetaProjectMirror(self, m): | 956 | def _AddMetaProjectMirror(self, m): |
954 | name = None | 957 | name = None |
955 | m_url = m.GetRemote(m.remote.name).url | 958 | m_url = m.GetRemote(m.remote.name).url |
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 59f2a779..20459d1d 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
@@ -265,6 +265,19 @@ class XmlManifestTests(ManifestParseTestCase): | |||
265 | self.assertEqual(manifest.repo_hooks_project.name, 'repohooks') | 265 | self.assertEqual(manifest.repo_hooks_project.name, 'repohooks') |
266 | self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b']) | 266 | self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b']) |
267 | 267 | ||
268 | def test_repo_hooks_unordered(self): | ||
269 | """Check repo-hooks settings work even if the project def comes second.""" | ||
270 | manifest = self.getXmlManifest(""" | ||
271 | <manifest> | ||
272 | <remote name="test-remote" fetch="http://localhost" /> | ||
273 | <default remote="test-remote" revision="refs/heads/main" /> | ||
274 | <repo-hooks in-project="repohooks" enabled-list="a, b"/> | ||
275 | <project name="repohooks" path="src/repohooks"/> | ||
276 | </manifest> | ||
277 | """) | ||
278 | self.assertEqual(manifest.repo_hooks_project.name, 'repohooks') | ||
279 | self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b']) | ||
280 | |||
268 | def test_unknown_tags(self): | 281 | def test_unknown_tags(self): |
269 | """Check superproject settings.""" | 282 | """Check superproject settings.""" |
270 | manifest = self.getXmlManifest(""" | 283 | manifest = self.getXmlManifest(""" |