set -euo pipefail
changed_rs=$(git diff --cached --name-only --diff-filter=ACM | grep '\.rs$' || true)
if [ -n "$changed_rs" ]; then
cargo fmt --check 2>&1 \
|| { echo "Run 'cargo fmt' then re-stage."; exit 1; }
cargo clippy --all-targets -- -D warnings 2>&1 \
|| { echo "Fix clippy warnings before committing."; exit 1; }
fi