pre-commit 698 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. # Pre-commit hook: ensures formatting and tests pass before committing
  3. echo "Running pre-commit checks..."
  4. # 1. Check formatting on staged files
  5. STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|json|md)$')
  6. if [ -n "$STAGED_FILES" ]; then
  7. echo "Checking format..."
  8. echo "$STAGED_FILES" | xargs deno fmt --check
  9. if [ $? -ne 0 ]; then
  10. echo ""
  11. echo "Format check failed. Run 'deno fmt' to fix, then stage the changes."
  12. exit 1
  13. fi
  14. fi
  15. # 2. Run all tests
  16. echo "Running tests..."
  17. deno task test
  18. if [ $? -ne 0 ]; then
  19. echo ""
  20. echo "Tests failed. Fix the failing tests before committing."
  21. exit 1
  22. fi
  23. echo "All checks passed."