diff options
-rw-r--r-- | docs/manifest-format.md | 17 | ||||
-rw-r--r-- | manifest_xml.py | 16 | ||||
-rw-r--r-- | tests/test_manifest_xml.py | 13 |
3 files changed, 40 insertions, 6 deletions
diff --git a/docs/manifest-format.md b/docs/manifest-format.md index 2af34ac2..0201c88b 100644 --- a/docs/manifest-format.md +++ b/docs/manifest-format.md | |||
@@ -111,6 +111,10 @@ A description of the elements and their attributes follows. | |||
111 | 111 | ||
112 | The root element of the file. | 112 | The root element of the file. |
113 | 113 | ||
114 | ### Element notice | ||
115 | |||
116 | Arbitrary text that is displayed to users whenever `repo sync` finishes. | ||
117 | The content is simply passed through as it exists in the manifest. | ||
114 | 118 | ||
115 | ### Element remote | 119 | ### Element remote |
116 | 120 | ||
@@ -360,6 +364,19 @@ This element is mostly useful in a local manifest file, where | |||
360 | the user can remove a project, and possibly replace it with their | 364 | the user can remove a project, and possibly replace it with their |
361 | own definition. | 365 | own definition. |
362 | 366 | ||
367 | ### Element repo-hooks | ||
368 | |||
369 | NB: See the [practical documentation](./repo-hooks.md) for using repo hooks. | ||
370 | |||
371 | Only one repo-hooks element may be specified at a time. | ||
372 | Attempting to redefine it will fail to parse. | ||
373 | |||
374 | Attribute `in-project`: The project where the hooks are defined. The value | ||
375 | must match the `name` attribute (**not** the `path` attribute) of a previously | ||
376 | defined `project` element. | ||
377 | |||
378 | Attribute `enabled-list`: List of hooks to use, whitespace or comma separated. | ||
379 | |||
363 | ### Element include | 380 | ### Element include |
364 | 381 | ||
365 | This element provides the capability of including another manifest | 382 | This element provides the capability of including another manifest |
diff --git a/manifest_xml.py b/manifest_xml.py index ad0017cc..00659316 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -292,8 +292,12 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
292 | if r.revision is not None: | 292 | if r.revision is not None: |
293 | e.setAttribute('revision', r.revision) | 293 | e.setAttribute('revision', r.revision) |
294 | 294 | ||
295 | def _ParseGroups(self, groups): | 295 | def _ParseList(self, field): |
296 | return [x for x in re.split(r'[,\s]+', groups) if x] | 296 | """Parse fields that contain flattened lists. |
297 | |||
298 | These are whitespace & comma separated. Empty elements will be discarded. | ||
299 | """ | ||
300 | return [x for x in re.split(r'[,\s]+', field) if x] | ||
297 | 301 | ||
298 | def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None): | 302 | def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None): |
299 | """Return the current manifest XML.""" | 303 | """Return the current manifest XML.""" |
@@ -302,7 +306,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
302 | if groups is None: | 306 | if groups is None: |
303 | groups = mp.config.GetString('manifest.groups') | 307 | groups = mp.config.GetString('manifest.groups') |
304 | if groups: | 308 | if groups: |
305 | groups = self._ParseGroups(groups) | 309 | groups = self._ParseList(groups) |
306 | 310 | ||
307 | doc = xml.dom.minidom.Document() | 311 | doc = xml.dom.minidom.Document() |
308 | root = doc.createElement('manifest') | 312 | root = doc.createElement('manifest') |
@@ -754,7 +758,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
754 | path = node.getAttribute('path') | 758 | path = node.getAttribute('path') |
755 | groups = node.getAttribute('groups') | 759 | groups = node.getAttribute('groups') |
756 | if groups: | 760 | if groups: |
757 | groups = self._ParseGroups(groups) | 761 | groups = self._ParseList(groups) |
758 | revision = node.getAttribute('revision') | 762 | revision = node.getAttribute('revision') |
759 | remote = node.getAttribute('remote') | 763 | remote = node.getAttribute('remote') |
760 | if remote: | 764 | if remote: |
@@ -776,7 +780,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
776 | if node.nodeName == 'repo-hooks': | 780 | if node.nodeName == 'repo-hooks': |
777 | # Get the name of the project and the (space-separated) list of enabled. | 781 | # Get the name of the project and the (space-separated) list of enabled. |
778 | repo_hooks_project = self._reqatt(node, 'in-project') | 782 | repo_hooks_project = self._reqatt(node, 'in-project') |
779 | enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() | 783 | enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) |
780 | 784 | ||
781 | # Only one project can be the hooks project | 785 | # Only one project can be the hooks project |
782 | if self._repo_hooks_project is not None: | 786 | if self._repo_hooks_project is not None: |
@@ -989,7 +993,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
989 | groups = '' | 993 | groups = '' |
990 | if node.hasAttribute('groups'): | 994 | if node.hasAttribute('groups'): |
991 | groups = node.getAttribute('groups') | 995 | groups = node.getAttribute('groups') |
992 | groups = self._ParseGroups(groups) | 996 | groups = self._ParseList(groups) |
993 | 997 | ||
994 | if parent is None: | 998 | if parent is None: |
995 | relpath, worktree, gitdir, objdir, use_git_worktrees = \ | 999 | relpath, worktree, gitdir, objdir, use_git_worktrees = \ |
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 939717be..2a8c3f66 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
@@ -212,6 +212,19 @@ class XmlManifestTests(unittest.TestCase): | |||
212 | '<manifest></manifest>') | 212 | '<manifest></manifest>') |
213 | self.assertEqual(manifest.ToDict(), {}) | 213 | self.assertEqual(manifest.ToDict(), {}) |
214 | 214 | ||
215 | def test_repo_hooks(self): | ||
216 | """Check repo-hooks settings.""" | ||
217 | manifest = self.getXmlManifest(""" | ||
218 | <manifest> | ||
219 | <remote name="test-remote" fetch="http://localhost" /> | ||
220 | <default remote="test-remote" revision="refs/heads/main" /> | ||
221 | <project name="repohooks" path="src/repohooks"/> | ||
222 | <repo-hooks in-project="repohooks" enabled-list="a, b"/> | ||
223 | </manifest> | ||
224 | """) | ||
225 | self.assertEqual(manifest.repo_hooks_project.name, 'repohooks') | ||
226 | self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b']) | ||
227 | |||
215 | def test_project_group(self): | 228 | def test_project_group(self): |
216 | """Check project group settings.""" | 229 | """Check project group settings.""" |
217 | manifest = self.getXmlManifest(""" | 230 | manifest = self.getXmlManifest(""" |