set -euo pipefail
if git diff --cached --name-only | grep -Eq '(^|/)Cargo\.lock$'; then
echo "error: Cargo.lock must not be committed in library repositories (it should be gitignored)." >&2
exit 1
fi
if ! git diff --cached --name-only | grep -qE '\.rs$|Cargo\.toml$'; then
exit 0
fi
if rustup run nightly rustfmt --version >/dev/null 2>&1; then
echo "pre-commit: checking formatting..."
cargo +nightly fmt --all -- --check
fi
echo "pre-commit: running clippy..."
cargo clippy --all-targets -- -D warnings