set -e
ensure_cargo() {
if command -v cargo >/dev/null 2>&1; then
return 0
fi
if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
if command -v cargo >/dev/null 2>&1; then
return 0
fi
if [ -x "$HOME/.cargo/bin/cargo" ]; then
PATH="$HOME/.cargo/bin:$PATH"
export PATH
return 0
fi
echo ""
echo "✗ RUST TOOLCHAIN NOT FOUND"
echo " cargo is not available in the git hook environment."
echo " Install Rust or source ~/.cargo/env, then try again."
exit 1
}
ensure_cargo
echo "╔══════════════════════════════════════════╗"
echo "║ nanodock Pre-Commit Quality Gate ║"
echo "╚══════════════════════════════════════════╝"
echo ""
echo "→ Checking formatting..."
if ! cargo fmt --all -- --check; then
echo ""
echo "✗ FORMATTING FAILED"
echo " Run: cargo fmt"
echo " Then try committing again."
exit 1
fi
echo " ✓ Formatting OK"
echo "→ Running cross-target clippy..."
if ! sh scripts/check-platform-clippy.sh; then
echo ""
echo "✗ CLIPPY FAILED"
echo " Fix the lint errors above or install the missing rustup targets,"
echo " then try committing again."
exit 1
fi
echo " ✓ Cross-target clippy OK"
echo "→ Running tests..."
if ! cargo test --lib --tests; then
echo ""
echo "✗ TESTS FAILED"
echo " Fix the failing unit or integration tests, then try committing again."
exit 1
fi
if ! cargo test --doc; then
echo ""
echo "✗ TESTS FAILED"
echo " Fix the failing doctests, then try committing again."
exit 1
fi
echo " ✓ Tests OK"
echo ""
echo "✓ All quality gates passed. Committing..."