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

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

if ! command -v git >/dev/null 2>&1; then
  echo "git is required" >&2
  exit 1
fi

if [[ ! -d "$ROOT/.git" ]]; then
  echo "Not a git repository: $ROOT" >&2
  exit 1
fi

chmod +x "$ROOT/.githooks/pre-commit"
chmod +x "$ROOT/.githooks/commit-msg"
chmod +x "$ROOT/.githooks/pre-push"
git -C "$ROOT" config core.hooksPath .githooks

echo "Installed git hooks. core.hooksPath=.githooks"
