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

# Pre-commit hook for rust-fafb-q
#
# Install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
# Or:      ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
#
# Checks:
#   1. cargo fmt -- --check       (formatting)
#   2. cargo clippy                (lints)
#   3. cargo test --no-run         (test compilation)
#   4. cargo bench --no-run        (bench compilation)
#
# The bench check catches API drift between library code and benchmarks,
# which are not compiled during `cargo test`.

echo "── pre-commit: checking formatting ──"
cargo fmt -- --check

echo "── pre-commit: checking clippy ──"
cargo clippy -- -D warnings

echo "── pre-commit: compiling tests ──"
cargo test --no-run --quiet 2>&1 | tail -5

echo "── pre-commit: compiling benchmarks ──"
cargo bench --no-run --quiet 2>&1 | tail -5

echo "── pre-commit: all checks passed ──"
