set -e
echo "🔍 Running pre-commit checks..."
echo ""
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_status() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}✓${NC} $2"
else
echo -e "${RED}✗${NC} $2"
return 1
fi
}
FAILED=0
echo "📋 Running tests..."
if cargo test --quiet 2>&1 | grep -q "test result: ok"; then
print_status 0 "Tests passed"
else
print_status 1 "Tests failed"
FAILED=1
fi
echo ""
echo "📎 Running clippy..."
if cargo clippy --all-targets --all-features -- -D warnings 2>&1 | tail -1 | grep -q "Finished"; then
print_status 0 "Clippy passed"
else
print_status 1 "Clippy found issues"
FAILED=1
fi
echo ""
echo "✨ Checking format..."
if cargo fmt --all -- --check > /dev/null 2>&1; then
print_status 0 "Format check passed"
else
print_status 1 "Format check failed - run 'cargo fmt' to fix"
FAILED=1
fi
echo ""
echo "📚 Building documentation..."
if cargo doc --no-deps --all-features --quiet > /dev/null 2>&1; then
print_status 0 "Documentation built successfully"
else
print_status 1 "Documentation build failed"
FAILED=1
fi
echo ""
if [ $FAILED -eq 1 ]; then
echo -e "${RED}❌ Pre-commit checks failed. Please fix the issues above.${NC}"
echo ""
echo "To skip this hook (not recommended), use: git commit --no-verify"
exit 1
fi
echo -e "${GREEN}✅ All pre-commit checks passed!${NC}"
echo ""
exit 0