Files
dnswatcher/script/install-precommit
T
sneak b09d7caf4d
check / check (push) Successful in 1m27s
script/install-precommit: ask git where hooks live (closes #129)
The script wrote the hook to .git/hooks, which fails when .git is a
file rather than a directory, as in a clone made with
--separate-git-dir. It now asks git for the hooks directory with
`git rev-parse --git-path hooks` and creates it if missing. In an
ordinary clone git answers .git/hooks, so nothing moves there. Where
core.hooksPath is set, git answers that directory, so the hook now
lands where git runs it instead of in .git/hooks, where it never ran.

Model: opus-5-5
2026-10-01 17:57:36 +00:00

21 lines
618 B
Bash
Executable File

#!/bin/sh
# script/install-precommit: install the git pre-commit hook that runs
# script/precommit. Our own extension to scripts-to-rule-them-all.
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
main() {
cd "$ROOT"
# Ask git where hooks live: .git is a file, not a directory, in some
# checkouts (for example a clone made with --separate-git-dir).
hooks="$(git rev-parse --git-path hooks)"
mkdir -p "$hooks"
hook="$hooks/pre-commit"
printf '#!/bin/sh\nset -e\nscript/precommit\n' > "$hook"
chmod +x "$hook"
echo "pre-commit hook installed: runs script/precommit"
}
main "$@"