#!/bin/sh
# Block commits that are not rustfmt-clean, mirroring the CI "Format and clippy" job so a
# formatting slip is caught locally instead of failing CI on a pushed commit.
#
# Enabled per-clone with:
#   git config core.hooksPath .githooks
#
# Bypass for a single commit (rarely needed) with `git commit --no-verify`.

if ! command -v cargo >/dev/null 2>&1; then
    echo "pre-commit: cargo not found on PATH; skipping rustfmt check" >&2
    exit 0
fi

if ! cargo fmt --check; then
    echo >&2
    echo "pre-commit: rustfmt check failed. Run 'cargo fmt' and re-stage before committing." >&2
    exit 1
fi
