#!/usr/bin/env bash # Pre-commit hook: format + test via tox. # Blocks the commit if formatting, imports, or tests fail. # Current baseline: ~18s wall-clock. Limit set to 30s for headroom. # # Auto-activated by `make install` via git core.hooksPath. set -e MAX_SECONDS=30 echo "Running pre-commit gate via tox (${MAX_SECONDS}s limit)..." # macOS lacks GNU timeout; use perl as a portable fallback. if command -v timeout &>/dev/null; then timeout "${MAX_SECONDS}" tox -e pre-commit else perl -e "alarm ${MAX_SECONDS}; exec @ARGV" -- tox -e pre-commit fi exit_code=$? # Re-stage any files that black/isort reformatted git add -u if [ "$exit_code" -eq 142 ] || [ "$exit_code" -eq 124 ]; then echo "" echo "BLOCKED: pre-commit gate exceeded ${MAX_SECONDS}s wall-clock limit." echo "Speed up slow tests before committing." exit 1 elif [ "$exit_code" -ne 0 ]; then echo "" echo "BLOCKED: pre-commit gate failed." exit 1 fi