Spaces:
Sleeping
Sleeping
| # Installs the pre-commit hook for this repo. | |
| # Idempotent: re-running overwrites the existing hook with the current template. | |
| set -euo pipefail | |
| REPO_ROOT="$(git rev-parse --show-toplevel)" | |
| HOOK_DIR="$REPO_ROOT/.git/hooks" | |
| HOOK_PATH="$HOOK_DIR/pre-commit" | |
| mkdir -p "$HOOK_DIR" | |
| cat > "$HOOK_PATH" <<'HOOK' | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| REPO_ROOT="$(git rev-parse --show-toplevel)" | |
| cd "$REPO_ROOT" | |
| if [ -f .venv/bin/activate ]; then | |
| # shellcheck disable=SC1091 | |
| source .venv/bin/activate | |
| fi | |
| echo "[pre-commit] ruff check ..." | |
| ruff check . | |
| echo "[pre-commit] pytest -q ..." | |
| pytest -q | |
| echo "[pre-commit] OK" | |
| HOOK | |
| chmod +x "$HOOK_PATH" | |
| echo "Pre-commit hook installed at $HOOK_PATH" | |