chore: make pre-commit resilient when cargo absent

This commit is contained in:
jasonwitty 2025-08-26 00:18:10 -07:00
parent c9ebea92f5
commit 3394beab67
2 changed files with 17 additions and 6 deletions

15
.githooks/pre-commit Normal file → Executable file
View File

@ -1,11 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# This repository uses a custom hooks directory (.githooks). To enable this pre-commit hook run:
# git config core.hooksPath .githooks
# Ensure this file is executable: chmod +x .githooks/pre-commit
set -euo pipefail set -euo pipefail
echo "[pre-commit] Running cargo fmt --all" >&2 echo "[pre-commit] Running cargo fmt --all" >&2
if ! command -v cargo >/dev/null 2>&1; then if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH" >&2 # Try loading rustup environment (common install path)
exit 1 if [ -f "$HOME/.cargo/env" ]; then
# shellcheck source=/dev/null
. "$HOME/.cargo/env"
fi
fi
if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH; skipping fmt (install Rust or adjust PATH)." >&2
exit 0
fi fi
cargo fmt --all cargo fmt --all