22
22
from git_refs import HEAD
23
23
24
24
25
+ # The API we've documented to hook authors. Keep in sync with repo-hooks.md.
26
+ _API_ARGS = {
27
+ "pre-upload" : {"project_list" , "worktree_list" },
28
+ }
29
+
30
+
25
31
class RepoHook :
26
32
"""A RepoHook contains information about a script to run as a hook.
27
33
@@ -56,6 +62,7 @@ def __init__(
56
62
hooks_project ,
57
63
repo_topdir ,
58
64
manifest_url ,
65
+ bug_url = None ,
59
66
bypass_hooks = False ,
60
67
allow_all_hooks = False ,
61
68
ignore_hooks = False ,
@@ -75,6 +82,7 @@ def __init__(
75
82
run with CWD as this directory.
76
83
If you have a manifest, this is manifest.topdir.
77
84
manifest_url: The URL to the manifest git repo.
85
+ bug_url: The URL to report issues.
78
86
bypass_hooks: If True, then 'Do not run the hook'.
79
87
allow_all_hooks: If True, then 'Run the hook without prompting'.
80
88
ignore_hooks: If True, then 'Do not abort action if hooks fail'.
@@ -85,6 +93,7 @@ def __init__(
85
93
self ._hooks_project = hooks_project
86
94
self ._repo_topdir = repo_topdir
87
95
self ._manifest_url = manifest_url
96
+ self ._bug_url = bug_url
88
97
self ._bypass_hooks = bypass_hooks
89
98
self ._allow_all_hooks = allow_all_hooks
90
99
self ._ignore_hooks = ignore_hooks
@@ -414,6 +423,20 @@ def Run(self, **kwargs):
414
423
ignore the result through the option combinations as listed in
415
424
AddHookOptionGroup().
416
425
"""
426
+ # Make sure our own callers use the documented API.
427
+ exp_kwargs = _API_ARGS .get (self ._hook_type , set ())
428
+ got_kwargs = set (kwargs .keys ())
429
+ if exp_kwargs != got_kwargs :
430
+ print (
431
+ "repo internal error: "
432
+ f"hook '{ self ._hook_type } ' called incorrectly\n "
433
+ f" got: { sorted (got_kwargs )} \n "
434
+ f" expected: { sorted (exp_kwargs )} \n "
435
+ f"Please file a bug: { self ._bug_url } " ,
436
+ file = sys .stderr ,
437
+ )
438
+ return False
439
+
417
440
# Do not do anything in case bypass_hooks is set, or
418
441
# no-op if there is no hooks project or if hook is disabled.
419
442
if (
@@ -472,6 +495,7 @@ def FromSubcmd(cls, manifest, opt, *args, **kwargs):
472
495
"manifest_url" : manifest .manifestProject .GetRemote (
473
496
"origin"
474
497
).url ,
498
+ "bug_url" : manifest .contactinfo .bugurl ,
475
499
}
476
500
)
477
501
return cls (* args , ** kwargs )
0 commit comments