|
|
@@ -1,20 +1,21 @@
|
|
|
#!/bin/sh
|
|
|
|
|
|
-# Pre-commit hook: ensures formatting and tests pass before committing
|
|
|
+# Pre-commit hook: auto-formats staged files and ensures tests pass before committing
|
|
|
|
|
|
echo "Running pre-commit checks..."
|
|
|
|
|
|
-# 1. Check formatting on staged files
|
|
|
+# 1. Auto-format staged files
|
|
|
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|json|md)$')
|
|
|
|
|
|
if [ -n "$STAGED_FILES" ]; then
|
|
|
- echo "Checking format..."
|
|
|
- echo "$STAGED_FILES" | xargs deno fmt --check
|
|
|
+ echo "Auto-formatting..."
|
|
|
+ echo "$STAGED_FILES" | xargs deno fmt
|
|
|
if [ $? -ne 0 ]; then
|
|
|
echo ""
|
|
|
- echo "Format check failed. Run 'deno fmt' to fix, then stage the changes."
|
|
|
+ echo "Auto-format failed. Fix the issues manually and try again."
|
|
|
exit 1
|
|
|
fi
|
|
|
+ echo "$STAGED_FILES" | xargs git add
|
|
|
fi
|
|
|
|
|
|
# 2. Run all tests
|