diff options
| author | Rahul Yadav <yadavrah@google.com> | 2026-07-10 08:39:24 -0700 |
|---|---|---|
| committer | gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2026-07-20 07:56:03 -0700 |
| commit | eeba6f268d0220bc928ed7af41d310dfbe215205 (patch) | |
| tree | 60dbb9793ede294214181e175c9c92a8d6fc6ae9 /tests/test_hooks.py | |
| parent | 1729aaebaed8912cec20e5191d961400c08e98b1 (diff) | |
| download | git-repo-eeba6f268d0220bc928ed7af41d310dfbe215205.tar.gz | |
hooks: pass yes flag when available
Pass the -y flag as a keyword argument "yes" to the hook main function.
This allows upload hooks (such as auto-fixers) to automatically
apply fixes when the -y flag is passed, rather than prompting the user.
Bug: 498893733
Change-Id: I12096029aa3af471ba9175314d749deb0ebd1007
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/605261
Commit-Queue: Rahul Yadav <yadavrah@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Rahul Yadav <yadavrah@google.com>
Diffstat (limited to 'tests/test_hooks.py')
| -rw-r--r-- | tests/test_hooks.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 14c226c75..33ccba7b6 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py | |||
| @@ -105,3 +105,37 @@ def test_post_sync_argument_validation() -> None: | |||
| 105 | 105 | ||
| 106 | finally: | 106 | finally: |
| 107 | sys.stderr = old_stderr | 107 | sys.stderr = old_stderr |
| 108 | |||
| 109 | |||
| 110 | @pytest.mark.parametrize("yes_val", (True, False)) | ||
| 111 | def test_repo_upload_yes_arg(tmp_path, yes_val: bool) -> None: | ||
| 112 | """Test that yes is passed in kwargs during hook execution.""" | ||
| 113 | |||
| 114 | class FakeProject: | ||
| 115 | def __init__(self, worktree): | ||
| 116 | self.worktree = worktree | ||
| 117 | self.enabled_repo_hooks = ["pre-upload"] | ||
| 118 | self.config = None | ||
| 119 | |||
| 120 | hook_file = tmp_path / "pre-upload.py" | ||
| 121 | |||
| 122 | hook_content = """ | ||
| 123 | def main(project_list, **kwargs): | ||
| 124 | project_list.append(kwargs.get("yes")) | ||
| 125 | """ | ||
| 126 | hook_file.write_text(hook_content) | ||
| 127 | |||
| 128 | hook = hooks.RepoHook( | ||
| 129 | hook_type="pre-upload", | ||
| 130 | hooks_project=FakeProject(str(tmp_path)), | ||
| 131 | repo_topdir=str(tmp_path), | ||
| 132 | manifest_url="https://gerrit", | ||
| 133 | allow_all_hooks=True, | ||
| 134 | yes=yes_val, | ||
| 135 | ) | ||
| 136 | |||
| 137 | project_list = [] | ||
| 138 | res = hook.Run(project_list=project_list, worktree_list=[]) | ||
| 139 | |||
| 140 | assert res is True | ||
| 141 | assert project_list == [yes_val] | ||
