#!/usr/bin/env bash
#
# Installs the repo's shared git hooks by pointing git at scripts/hooks.
# Run once per clone:
#
#   ./scripts/install-hooks.sh
#
# Uses `git config --local core.hooksPath` so the config is clone-scoped
# (not committed into shared git config). Hooks themselves ARE tracked
# in scripts/hooks/ so every developer gets the same behavior.

set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
HOOKS_DIR="scripts/hooks"

cd "$ROOT"

if [ ! -d "$HOOKS_DIR" ]; then
    echo "error: $HOOKS_DIR not found at repo root ($ROOT)" >&2
    exit 1
fi

# Make every hook file executable.
chmod +x "$HOOKS_DIR"/* 2>/dev/null || true

git config --local core.hooksPath "$HOOKS_DIR"

echo "[install-hooks] core.hooksPath = $HOOKS_DIR"
echo "[install-hooks] installed hooks:"
for h in "$HOOKS_DIR"/*; do
    [ -f "$h" ] && echo "  - $(basename "$h")"
done
