diff options
| author | Rahul Yadav <yadavrah@google.com> | 2026-08-14 15:09:22 +0000 |
|---|---|---|
| committer | gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2026-08-27 03:28:58 -0700 |
| commit | e6ad7080098a0db0cb304812c8603856da2bebf2 (patch) | |
| tree | 748d6b5e3983a874c34177da480330f676b29ba2 /docs | |
| parent | 09914bcab7d1d5570c20a52d1861957145da8a5a (diff) | |
| download | git-repo-e6ad7080098a0db0cb304812c8603856da2bebf2.tar.gz git-repo-e6ad7080098a0db0cb304812c8603856da2bebf2.zip | |
hooks: add --fix option to auto-apply hook fixes
Pass the --fix flag as a keyword argument "fix" to the hook main
function. This allows hooks (such as git-repohooks) to decouple
automated fix application from the -y/--yes flag so that -y can
answer yes to upload confirmation prompts without triggering file
mutations.
Companion change in git-repohooks:
https://gerrit-review.googlesource.com/c/git-repohooks/+/621761
Bug: 546510319
Test: python3 -m pytest tests/test_hooks.py
Change-Id: If0288d4791fc0a2aba6e88854e3aa81b0923b664
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/619281
Commit-Queue: Rahul Yadav <yadavrah@google.com>
Tested-by: Rahul Yadav <yadavrah@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/repo-hooks.md | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/docs/repo-hooks.md b/docs/repo-hooks.md index c3adee8ad..7f69217da 100644 --- a/docs/repo-hooks.md +++ b/docs/repo-hooks.md @@ -88,7 +88,14 @@ be useful when deploying automatic fixes. If the repo command that triggered the hook supports a "yes" option (e.g., `repo upload --yes`), this option is propagated to the hook's `main` function as `yes` parameter (defaulting to `False`). Hooks can use this to bypass -interactive confirmation prompts when they can automatically fix issues. +interactive confirmation prompts for safe non-modifying operations. + +### Automated Fixes + +If the repo command that triggered the hook supports a "fix" option (e.g., +`repo upload --fix`), this option is propagated to the hook's `main` function +as `fix` parameter (defaulting to `False`). Hooks can use this to automatically +apply fixes without prompting the user. ### Shebang Handling @@ -126,7 +133,7 @@ This hook runs when people run `repo upload`. The `pre-upload.py` file should be defined like: ```py -def main(project_list, worktree_list=None, yes=False, **kwargs): +def main(project_list, worktree_list=None, fix=False, yes=False, **kwargs): """Main function invoked directly by repo. We must use the name "main" as that is what repo requires. @@ -137,6 +144,7 @@ def main(project_list, worktree_list=None, yes=False, **kwargs): project_list, so that each entry in project_list matches with a directory in worktree_list. If None, we will attempt to calculate the directories automatically. + fix: Whether to automatically apply fixes without prompting. yes: Whether to answer yes to all safe prompts (see [Safe Prompts](#safe-prompts)). kwargs: Leave this here for forward-compatibility. |
