When git's core.hooksPath is configured globally, running prek install -f inside a repository produces the following error:
❯ prek install -f
error: Refusing to install hooks because core.hooksPath is configured outside this repository.
note: Git will execute hooks from the configured global/system hooks directory, not from this repository's hooks directory.
The -f (force) flag does not override this check.
Why do we need to install the hook? Because even if core.hooksPath is set, the local hook can still be executed via the global hook, such as the following pre-commit script:
#!/usr/bin/env bash
LOCAL_HOOK=".git/hooks/pre-commit"
if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then
"$LOCAL_HOOK" "$@"
exit "$?"
fi
exit 0
The expected behavior is that -f would bypass the error and proceed with the installation, and simply emit a warning about the global hooksPath interfering.
Alternatively, if you made prek install (without -f) emit a warning about core.hooksPath instead of throwing an error, I would be even happier.
When git's
core.hooksPathis configured globally, runningprek install -finside a repository produces the following error:❯ prek install -f error: Refusing to install hooks because core.hooksPath is configured outside this repository. note: Git will execute hooks from the configured global/system hooks directory, not from this repository's hooks directory.The
-f(force) flag does not override this check.Why do we need to install the hook? Because even if
core.hooksPathis set, the local hook can still be executed via the global hook, such as the followingpre-commitscript:The expected behavior is that
-fwould bypass the error and proceed with the installation, and simply emit a warning about the global hooksPath interfering.Alternatively, if you made
prek install(without -f) emit a warning aboutcore.hooksPathinstead of throwing an error, I would be even happier.