nixpkgs/pkgs/tools/misc/pre-commit/hook-tmpl.patch
Rebecca Turner 5a01cf1084
pre-commit: use absolute path for binary in hook
This changes the generated Git hook to refer to the `pre-commit` binary
by its absolute path. This means that Git hooks created with
`nix-shell --run 'pre-commit install'` or similar will be usable outside
of the Nix shell they were created in.

I think this is the intended behavior for this package, considering that
the `postPatch` phase already includes a substitution for this variable,
otherwise unused:

    substituteInPlace pre_commit/resources/hook-tmpl \
      --subst-var-by pre-commit $out
2022-10-07 13:38:15 -04:00

18 lines
618 B
Diff

diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl
index 53d29f9..9b5dc2c 100755
--- a/pre_commit/resources/hook-tmpl
+++ b/pre_commit/resources/hook-tmpl
@@ -10,11 +10,4 @@ ARGS=(hook-impl)
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
-if [ -x "$INSTALL_PYTHON" ]; then
- exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
-elif command -v pre-commit > /dev/null; then
- exec pre-commit "${ARGS[@]}"
-else
- echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
- exit 1
-fi
+exec @pre-commit@/bin/pre-commit "${ARGS[@]}"