From b0f769d186ca08a6e80eab10b6b6d45985092ec3 Mon Sep 17 00:00:00 2001 From: Hermes Date: Wed, 3 Jun 2026 23:42:31 +0000 Subject: [PATCH] feat(hooks): run PHPUnit in pre-commit hook (#67) Erweitert den Husky pre-commit-Hook um einen PHPUnit-Schritt. Ausserdem wird scripts/safe-commit.sh aktualisiert, damit das Safety-Net dieselbe Logik wie der Hook verwendet (kein doppelter Code). Vorher: Hook rief nur 'npx lint-staged' auf. Nachher: Hook ruft scripts/pre-commit-checks.sh auf, das - lint-staged ausfuehrt (unveraendert) - PHPUnit nur dann ausfuehrt, wenn PHP-relevante Dateien gestaged sind (Performance-Optimierung: Issue #67 Anforderung) - Bei Test-Fehler den Commit mit Exit-Code 1 abbricht Closes #67 --- .husky/pre-commit | 4 +++- scripts/safe-commit.sh | 16 ++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 2312dc5..40620f1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,3 @@ -npx lint-staged +# Delegiert an scripts/pre-commit-checks.sh +# (gleiche Logik wie safe-commit.sh-Safety-Net, nur einmalig) +./scripts/pre-commit-checks.sh diff --git a/scripts/safe-commit.sh b/scripts/safe-commit.sh index 6e0c7f7..0f8dacb 100755 --- a/scripts/safe-commit.sh +++ b/scripts/safe-commit.sh @@ -2,7 +2,7 @@ # safe-commit.sh – Commit with pre-commit hooks guaranteed to run # Usage: ./scripts/safe-commit.sh "commit message" # -# This script ensures lint checks always execute, even when committing +# This script ensures lint + PHPUnit checks always execute, even when committing # from non-interactive contexts (CI, AI agents, etc.). set -euo pipefail @@ -21,17 +21,9 @@ if [ -d ".husky" ]; then git config core.hooksPath .husky fi -# Run lint-staged manually as a safety net (in case hook is skipped) -if command -v npx &>/dev/null && [ -f "node_modules/.bin/lint-staged" ]; then - echo "🔍 Running pre-commit lint checks..." - npx lint-staged || { - echo "" - echo "❌ Lint checks failed. Commit aborted." - echo " Fix the errors above and try again." - exit 1 - } - echo "✅ All lint checks passed." -fi +# Run pre-commit checks manually as a safety net (in case hook is skipped) +# Same logic as .husky/pre-commit, just in case the hook is bypassed. +./scripts/pre-commit-checks.sh # Commit with hooks enabled (no --no-verify) git commit -m "$MSG"