#!/usr/bin/env bash
# Pre-commit guard: run `make ci` (registry + stack + tests) and block the
# commit on failure. Every commit must pass `make ci`; this file is the
# local-repo equivalent of the .github/workflows/ runner.
#
# Install once:
#     ln -sf ../../tools/git-hooks/pre-commit .git/hooks/pre-commit
# (relative symlink so the hook follows toolchain updates without re-installing.)
#
# Bypass deliberately (e.g., emergency WIP push to a branch you will rewrite):
#     git commit --no-verify

set -euo pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "$REPO_ROOT"

echo "pre-commit: running make ci"
if ! make ci; then
    echo
    echo "pre-commit: 'make ci' failed — commit blocked." >&2
    echo "Fix the failing checks, re-stage, and commit again." >&2
    exit 1
fi
