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>
This commit is contained in:
Rahul Yadav authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-07-20 07:56:03 -07:00
1 parent 1729aaebae
commit eeba6f268d
3 files changed
+53 -3

No files matched your search

+9 -2
View File
@@ -68,6 +68,7 @@ class RepoHook:
allow_all_hooks=False,
ignore_hooks=False,
abort_if_user_denies=False,
yes=False,
):
"""RepoHook constructor.
@@ -89,6 +90,7 @@ class RepoHook:
ignore_hooks: If True, then 'Do not abort action if hooks fail'.
abort_if_user_denies: If True, we'll abort running the hook if the
user doesn't allow us to run the hook.
yes: If True, then 'Yes' is assumed for any prompts.
"""
self._hook_type = hook_type
self._hooks_project = hooks_project
@@ -99,6 +101,7 @@ class RepoHook:
self._allow_all_hooks = allow_all_hooks
self._ignore_hooks = ignore_hooks
self._abort_if_user_denies = abort_if_user_denies
self._yes = yes
# Store the full path to the script for convenience.
self._script_fullpath = None
@@ -374,8 +377,11 @@ class RepoHook:
# def main(project_list, **kwargs):
#
# This allows us to later expand the API without breaking old hooks.
kwargs = kwargs.copy()
kwargs["hook_should_take_kwargs"] = True
kwargs = {
**kwargs,
"hook_should_take_kwargs": True,
"yes": self._yes,
}
# See what version of python the hook has been written against.
data = open(self._script_fullpath).read()
@@ -497,6 +503,7 @@ class RepoHook:
"origin"
).url,
"bug_url": manifest.contactinfo.bugurl,
"yes": getattr(opt, "yes", False),
}
)
return cls(*args, **kwargs)