36 lines
803 B
Bash
Executable File
36 lines
803 B
Bash
Executable File
#!/bin/sh
|
|
# pre-commit hook: runs ruff check (lint) and ruff format --check on staged Python files
|
|
# To bypass: git commit --no-verify
|
|
|
|
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')
|
|
|
|
if [ -z "$STAGED_FILES" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
FAILED=0
|
|
|
|
echo "🔍 Running ruff check (lint)..."
|
|
uv run ruff check $STAGED_FILES
|
|
if [ $? -ne 0 ]; then
|
|
echo " ↳ Fix with: uv run ruff check --fix"
|
|
FAILED=1
|
|
fi
|
|
|
|
echo "🎨 Running ruff format --check..."
|
|
uv run ruff format --check $STAGED_FILES
|
|
if [ $? -ne 0 ]; then
|
|
echo " ↳ Fix with: uv run ruff format"
|
|
FAILED=1
|
|
fi
|
|
|
|
if [ $FAILED -ne 0 ]; then
|
|
echo ""
|
|
echo "❌ Pre-commit checks failed. Commit aborted."
|
|
echo " To bypass: git commit --no-verify"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ All checks passed."
|
|
exit 0
|