diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py index d19e0d47..572d702d 100644 --- a/pre_commit/commands/install_uninstall.py +++ b/pre_commit/commands/install_uninstall.py @@ -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`', diff --git a/pre_commit/main.py b/pre_commit/main.py index 9dfce2c2..10452224 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -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(