#!/usr/bin/env bash
set -euo pipefail

ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
if [[ -z "${ROOT}" ]]; then
  echo "error: not inside a git repository" >&2
  exit 1
fi

cd "${ROOT}"

if [[ ! -d ".githooks" ]]; then
  echo "error: .githooks/ not found (expected at repo root)" >&2
  exit 1
fi

git config core.hooksPath .githooks

if [[ -f ".githooks/pre-commit" ]]; then
  chmod +x .githooks/pre-commit || true
fi

echo "Configured git hooks path: core.hooksPath=.githooks"
echo "Active hooks:"
ls -1 .githooks | sed 's/^/- /'

