Install hooks by copying into .git/hooks instead of core.hooksPath
Linking core.hooksPath to the tracked, sandbox-writable .githooks/ let a sandboxed command rewrite a hook that git commit/push then run unsandboxed. Copies in .git/hooks can't be changed from the sandbox. This also keeps existing .git/hooks scripts working and lets npm install succeed outside a git checkout. pre-merge-commit now names itself in errors; hook tests clean up, ignore GIT_* env and cover the installer; docs state what each layer does and doesn't stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b08c7b27a
commit
24541f0602
7 files changed
+72
-20
No files matched your search
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/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")/.."
|
||||
if ! hooks=$(git rev-parse --git-path hooks 2>/dev/null); then
|
||||
echo "install-hooks: not a git checkout; skipping." >&2
|
||||
exit 0
|
||||
fi
|
||||
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"
|
||||
Reference in new issue
Block a user