set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "Running pre-commit checks..."
echo ""
FAILED=0
echo -n "Checking formatting... "
if ! cargo fmt --all --check > /dev/null 2>&1; then
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Fix with:${NC} cargo fmt --all"
FAILED=1
else
echo -e "${GREEN}OK${NC}"
fi
echo -n "Running clippy... "
if ! cargo clippy --all-targets -- -D warnings > /dev/null 2>&1; then
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Run:${NC} cargo clippy --all-targets"
FAILED=1
else
echo -e "${GREEN}OK${NC}"
fi
echo -n "Running tests... "
if ! cargo test --quiet > /dev/null 2>&1; then
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Run:${NC} cargo test"
FAILED=1
else
echo -e "${GREEN}OK${NC}"
fi
if git diff --cached --name-only | grep -q "pyproject.toml"; then
echo -n "Updating uv.lock... "
if ! uv lock > /dev/null 2>&1; then
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Run:${NC} uv lock"
FAILED=1
else
git add uv.lock
echo -e "${GREEN}OK${NC}"
fi
fi
echo ""
if [ $FAILED -ne 0 ]; then
echo -e "${RED}Pre-commit checks failed.${NC}"
echo "Bypass with: git commit --no-verify"
exit 1
fi
echo -e "${GREEN}All checks passed!${NC}"