colibri/scripts/install-hooks.sh
Sam & Claude 9f091454e5
Some checks failed
CI / rust (pull_request) Has been cancelled
CI / markdown (pull_request) Has been cancelled
CI / port (pull_request) Has been cancelled
CI / agent-jail-pkgs (pull_request) Has been cancelled
fix(hooks): make install-hooks robust for worktrees/custom git dirs
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.
2026-06-24 14:13:06 +02:00

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}"