#!/usr/bin/env bash # Pre-commit hook: format check + integration tests for the czsplicer CLI. # Install (from repo root): git config core.hooksPath hooks # or: cp hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit set -euo pipefail # Resolve repo root regardless of where the hook was invoked from. REPO_ROOT="$(git rev-parse --show-toplevel)" cd "$REPO_ROOT" # Only run if Rust sources / manifests changed in this commit. if ! git diff --cached --name-only --diff-filter=ACMR | grep -qE '\.(rs|toml)$|^tests/'; then echo "[pre-commit] no Rust changes staged, skipping" exit 0 fi if ! command -v cargo >/dev/null 2>&1; then echo "[pre-commit] cargo not found; skipping checks" >&2 exit 0 fi echo "[pre-commit] cargo fmt --check" if ! cargo fmt --check; then echo "[pre-commit] formatting issues found — run 'cargo fmt' and re-stage" >&2 exit 1 fi echo "[pre-commit] cargo clippy -- -D warnings" if ! cargo clippy --quiet -- -D warnings; then echo "[pre-commit] clippy lint warnings found" >&2 exit 1 fi echo "[pre-commit] cargo test" if ! cargo test --quiet; then echo "[pre-commit] tests failed" >&2 exit 1 fi echo "[pre-commit] OK"