fix(hooks): use array-based file iteration for safety check
All checks were successful
Deploy Feature Branch to Test / PHP Syntax Check (push) Successful in 58s
Lint / PHP Syntax Check (push) Successful in 1m0s
Deploy Feature Branch to Test / HTML Lint (htmlhint) (push) Successful in 1m39s
Deploy Feature Branch to Test / CSS Lint (stylelint) (push) Successful in 1m42s
Deploy Feature Branch to Test / Deploy to Test Environment (push) Successful in 23s
Lint / HTML Lint (htmlhint) (push) Successful in 1m16s
Lint / CSS Lint (stylelint) (push) Successful in 1m21s
Lint / PHP Syntax Check (pull_request) Successful in 31s
Lint / CSS Lint (stylelint) (pull_request) Successful in 1m13s
Lint / HTML Lint (htmlhint) (pull_request) Successful in 1m4s

mapfile + array prevents word-splitting issues with filenames
containing spaces or other shell-special characters. Affects both
the affected-files listing and the stale-index safety check.

Without this fix, a filename like 'My Module.php' would be split
into 'My' and 'Module.php', causing the disk-existence check to
look for wrong paths.
This commit is contained in:
Hermes
2026-06-04 00:15:21 +00:00
parent b0f769d186
commit 3f1f0f5788

View File

@@ -28,25 +28,26 @@ fi
# - composer.json PHP-Abhaengigkeiten # - composer.json PHP-Abhaengigkeiten
# - composer.lock Lock-File # - composer.lock Lock-File
# ───────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────
PHP_TOUCHED=$(git diff --cached --name-only --diff-filter=ACMR \ # PHP-relevante Files (Array-basiert, robust gegen Spaces/Newlines in Filenames)
mapfile -t PHP_TOUCHED_ARR < <(git diff --cached --name-only --diff-filter=ACMR \
| grep -E '\.(php)$|^phpunit\.xml$|^composer\.(json|lock)$' || true) | grep -E '\.(php)$|^phpunit\.xml$|^composer\.(json|lock)$' || true)
if [ -n "$PHP_TOUCHED" ]; then if [ "${#PHP_TOUCHED_ARR[@]}" -gt 0 ]; then
echo "" echo ""
echo "==> PHP-Dateien geaendert -> PHPUnit wird ausgefuehrt" echo "==> PHP-Dateien geaendert -> PHPUnit wird ausgefuehrt"
echo " Betroffene Dateien:" echo " Betroffene Dateien:"
printf ' - %s\n' $PHP_TOUCHED printf ' - %s\n' "${PHP_TOUCHED_ARR[@]}"
# Safety-Check: alle gestaged PHP-Dateien muessen auf der Disk existieren. # Safety-Check: alle gestaged PHP-Dateien muessen auf der Disk existieren.
# Sonst wuerde PHPUnit eine inkonsistente Codebasis testen (Staged != Working Tree). # Sonst wuerde PHPUnit eine inkonsistente Codebasis testen (Staged != Working Tree).
MISSING="" MISSING=()
for f in $PHP_TOUCHED; do for f in "${PHP_TOUCHED_ARR[@]}"; do
[ -f "$f" ] || MISSING="$MISSING $f" [ -f "$f" ] || MISSING+=("$f")
done done
if [ -n "$MISSING" ]; then if [ "${#MISSING[@]}" -gt 0 ]; then
echo "" echo ""
echo "FEHLER: Gestaged PHP-Dateien existieren nicht auf der Disk:" echo "FEHLER: Gestaged PHP-Dateien existieren nicht auf der Disk:"
printf ' - %s\n' $MISSING printf ' - %s\n' "${MISSING[@]}"
echo " Loesung: 'git restore --staged <datei>' oder Working-Tree synchronisieren." echo " Loesung: 'git restore --staged <datei>' oder Working-Tree synchronisieren."
exit 1 exit 1
fi fi