Allow global core.hooksPath via --allow-global-hooks

This commit is contained in:
Luke Young 2023-09-06 11:34:35 -07:00
parent e2c6a822c7
commit f67f64306b
2 changed files with 14 additions and 1 deletions

View file

@ -118,9 +118,14 @@ def install(
overwrite: bool = False,
hooks: bool = False,
skip_on_missing_config: bool = False,
allow_global_hooks: bool = False,
git_dir: str | None = None,
) -> int:
if git_dir is None and git.has_core_hookpaths_set():
if (
git_dir is None and
git.has_core_hookpaths_set() and
not allow_global_hooks
):
logger.error(
'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
'hint: `git config --unset-all core.hooksPath`',

View file

@ -278,6 +278,13 @@ def main(argv: Sequence[str] | None = None) -> int:
'or exit with a failure code.'
),
)
install_parser.add_argument(
'--allow-global-hooks', action='store_true',
help=(
'Whether to allow installation of hooks if core.hooksPath '
'is configured in the global git configuration.'
),
)
install_hooks_parser = _add_cmd(
'install-hooks',
@ -399,6 +406,7 @@ def main(argv: Sequence[str] | None = None) -> int:
overwrite=args.overwrite,
hooks=args.install_hooks,
skip_on_missing_config=args.allow_missing_config,
allow_global_hooks=args.allow_global_hooks,
)
elif args.command == 'init-templatedir':
return init_templatedir(