The installer symlinked a RELATIVE target (../../scripts/pre-push), which only resolves for a standard <repo>/.git/hooks layout — it breaks in git worktrees or when .git is a file/elsewhere (both used by the agent harness), and assumed .git/hooks already exists. Resolve the real hooks dir via 'git rev-parse --git-path hooks' (worktree-safe), mkdir -p it, and symlink to the ABSOLUTE source path so it works regardless of where the hooks dir lives. Also verify pre-push exists + is executable. Tested: installs, link resolves to scripts/pre-push, idempotent.
24 lines
882 B
Bash
Executable file
24 lines
882 B
Bash
Executable file
#!/bin/sh
|
|
# Install git hooks for this clone. Run once per clone (idempotent).
|
|
#
|
|
# ./scripts/install-hooks.sh
|
|
#
|
|
# After this, every `git push` runs ci-checks.sh + wiki-lint --strict and
|
|
# rejects the push if the gate fails. Bypass only with --no-verify.
|
|
set -eu
|
|
|
|
repo_root="$(git rev-parse --show-toplevel)"
|
|
src="${repo_root}/scripts/pre-push"
|
|
[ -f "$src" ] || { echo "error: ${src} not found" >&2; exit 1; }
|
|
chmod +x "$src"
|
|
|
|
# --git-path resolves the real hooks dir even in worktrees / custom git dirs,
|
|
# where .git is a file or the hooks live outside <repo>/.git/hooks.
|
|
cd "$repo_root"
|
|
hooks_dir="$(git rev-parse --git-path hooks)"
|
|
mkdir -p "$hooks_dir"
|
|
|
|
# Symlink to the absolute source path → robust regardless of where the hooks
|
|
# dir actually lives (a relative target breaks for worktrees).
|
|
ln -sf "$src" "${hooks_dir}/pre-push"
|
|
echo "hooks installed: pre-push -> ${src}"
|