ref:main
#!/usr/bin/env bash
# Pre-commit hook: rustfmt + clippy on Rust changes.
#
# Enable for this checkout with: ./scripts/install-hooks.sh

set -euo pipefail

staged_rust=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.rs$' || true)

if [ -z "$staged_rust" ]; then
  exit 0
fi

echo "pre-commit: cargo fmt --all -- --check"
if ! cargo fmt --all -- --check; then
  echo "pre-commit: formatting failed. Run 'cargo fmt --all' and re-stage."
  exit 1
fi

echo "pre-commit: cargo clippy --all-targets --all-features -- -D warnings"
if ! cargo clippy --all-targets --all-features -- -D warnings; then
  echo "pre-commit: clippy failed. Fix the warnings and re-stage."
  exit 1
fi