2026-10-21 00:44:30 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Copy the hooks in .githooks/ into git's own hooks directory. They are copied rather than
|
|
|
|
|
# enabled with core.hooksPath on purpose: Claude Code's sandbox can't write inside .git/, so
|
|
|
|
|
# a sandboxed command can't rewrite the installed hooks, even though git commit and git push
|
|
|
|
|
# (and so their hooks) run outside the sandbox. Re-run after changing anything in .githooks/.
|
|
|
|
|
set -e
|
|
|
|
|
cd "$(dirname "$0")/.."
|
2026-10-21 00:55:32 +02:00
|
|
|
# Use the repo's own hooks directory, not `git rev-parse --git-path hooks`: that follows a
|
|
|
|
|
# (possibly global) core.hooksPath and would install these hooks for every repo.
|
|
|
|
|
if ! common=$(git rev-parse --git-common-dir 2>/dev/null); then
|
2026-10-21 00:44:30 +02:00
|
|
|
echo "install-hooks: not a git checkout; skipping." >&2
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
2026-10-21 00:55:32 +02:00
|
|
|
hooks="$common/hooks"
|
2026-10-21 00:44:30 +02:00
|
|
|
mkdir -p "$hooks"
|
|
|
|
|
for hook in .githooks/*; do
|
|
|
|
|
cp "$hook" "$hooks/"
|
|
|
|
|
chmod +x "$hooks/$(basename "$hook")"
|
|
|
|
|
done
|
|
|
|
|
echo "install-hooks: installed $(ls .githooks | tr '\n' ' ')into $hooks"
|