From b7c94badf4f8d84143654228897564430280669a Mon Sep 17 00:00:00 2001 From: "d.nakou@uu.nl" Date: Tue, 2 Dec 2025 17:24:17 +0100 Subject: [PATCH 1/6] squash --- bin/git/hooks/pre-commit | 45 ++++++++++++++++++++++++++++++++++++++++ bin/install-git-hooks.sh | 2 ++ 2 files changed, 47 insertions(+) create mode 100755 bin/git/hooks/pre-commit create mode 100755 bin/install-git-hooks.sh diff --git a/bin/git/hooks/pre-commit b/bin/git/hooks/pre-commit new file mode 100755 index 00000000..f08b2e80 --- /dev/null +++ b/bin/git/hooks/pre-commit @@ -0,0 +1,45 @@ +#!/bin/sh + +spinner() { + # PID of the background Pint process + pid="$1" + # How long the spinner should wait between frames + delay=0.1 + # Characters for spinner animation + spin='-\|/' +# Wait while the process is processing + while kill -0 "$pid" 2>/dev/null; do + # Spinner animation + c=$(printf "%s" "$spin" | cut -c1) # take first character + printf "\r%s Running Pint..." "$c" + # Spinner animation + spin=$(printf "%s" "$spin" | cut -c2-)"$(printf "%s" "$spin" | cut -c1)" + + sleep "$delay" + done + + printf "\rDone. \n" +} +# TODO do I check only for updated files? +# if not do this. +echo "Checking PHP code style…" + +# Run Pint in background +vendor/bin/pint --quiet & +# $! is the PID of the most recent background process. +spinner $! +# Statis of spinner which is the status of pint +STATUS=$? + +if [ $STATUS -eq 0 ]; then + + printf "\r✔ Pint completed successfully!\n" + + echo "Adding linted changes to Git…" + git add -u # Stages updated files only + + printf "✔ Changes have been staged.\n" +else + printf "\r✖ Pint found issues. Fixing needed.\n" + exit 1 +fi \ No newline at end of file diff --git a/bin/install-git-hooks.sh b/bin/install-git-hooks.sh new file mode 100755 index 00000000..8e2fa5b9 --- /dev/null +++ b/bin/install-git-hooks.sh @@ -0,0 +1,2 @@ +#!/bin/bash +cp -r bin/git/hooks/ .git/ \ No newline at end of file From 58d9a69938e60ca6b0d60d14b3ac558f424410ec Mon Sep 17 00:00:00 2001 From: "d.nakou@uu.nl" Date: Thu, 11 Dec 2025 16:26:41 +0100 Subject: [PATCH 2/6] fix and add prettier --- bin/git/hooks/pre-commit | 75 +++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/bin/git/hooks/pre-commit b/bin/git/hooks/pre-commit index f08b2e80..931c6817 100755 --- a/bin/git/hooks/pre-commit +++ b/bin/git/hooks/pre-commit @@ -20,26 +20,59 @@ spinner() { printf "\rDone. \n" } -# TODO do I check only for updated files? -# if not do this. -echo "Checking PHP code style…" - -# Run Pint in background -vendor/bin/pint --quiet & -# $! is the PID of the most recent background process. -spinner $! -# Statis of spinner which is the status of pint -STATUS=$? - -if [ $STATUS -eq 0 ]; then - - printf "\r✔ Pint completed successfully!\n" - - echo "Adding linted changes to Git…" - git add -u # Stages updated files only - - printf "✔ Changes have been staged.\n" + + +echo "Checking PHP and Blade code style…" + + +# Get relevant staged files +BLADE_FILES=$(git diff --cached --name-only -- '*.blade.php') +PHP_FILES=$(git diff --cached --name-only -- '*.php' ':!*.blade.php') + +PHP_STATUS=0 +BLADE_STATUS=0 + +if [ -z "$PHP_FILES" ]; then + echo "No staged PHP files to check." else - printf "\r✖ Pint found issues. Fixing needed.\n" + # Run Pint in background + vendor/bin/pint --quiet $PHP_FILES & + # $! is the PID of the most recent background process. + spinner $! + # Status of spinner which is the status of pint + PHP_STATUS=$? + + if [ $PHP_STATUS -eq 0 ]; then + printf "\r✔ Pint passed for PHP files!\n" + git add $PHP_FILES + else + printf "\r✖ Pint failed for PHP files.\n" + fi +fi + +# Similar procedure for blade files +if [ -z "$BLADE_FILES" ]; then + echo "No staged Blade files to check." +else + ./node_modules/.bin/prettier --write $BLADE_FILES & + spinner $! + BLADE_STATUS=$? + + if [ $BLADE_STATUS -eq 0 ]; then + printf "\r✔ Prettier passed for Blade files!\n" + git add $BLADE_FILES + else + printf "\r✖ Prettier failed for Blade files.\n" + fi +fi + +# if one check failed then exit +if [ $PHP_STATUS -ne 0 ] || [ $BLADE_STATUS -ne 0 ]; then + echo "" + echo "✖ Some staged files did not pass formatting checks." exit 1 -fi \ No newline at end of file +fi +# Else success`! +echo "" +echo "✔ All staged PHP and Blade files are correctly formatted!" +exit 0 \ No newline at end of file From 999e3958c1be489275e2129b84063d2039b4efc2 Mon Sep 17 00:00:00 2001 From: "d.nakou@uu.nl" Date: Thu, 11 Dec 2025 16:27:26 +0100 Subject: [PATCH 3/6] remove a comment --- bin/git/hooks/pre-commit | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/git/hooks/pre-commit b/bin/git/hooks/pre-commit index 931c6817..64083b1c 100755 --- a/bin/git/hooks/pre-commit +++ b/bin/git/hooks/pre-commit @@ -74,5 +74,4 @@ if [ $PHP_STATUS -ne 0 ] || [ $BLADE_STATUS -ne 0 ]; then fi # Else success`! echo "" -echo "✔ All staged PHP and Blade files are correctly formatted!" exit 0 \ No newline at end of file From 6590a42eb43b78e11c9b154484355b5543ed81d5 Mon Sep 17 00:00:00 2001 From: "d.nakou@uu.nl" Date: Thu, 11 Dec 2025 16:28:11 +0100 Subject: [PATCH 4/6] test commit --- bin/git/hooks/pre-commit | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/git/hooks/pre-commit b/bin/git/hooks/pre-commit index 64083b1c..e9c08c41 100755 --- a/bin/git/hooks/pre-commit +++ b/bin/git/hooks/pre-commit @@ -73,5 +73,4 @@ if [ $PHP_STATUS -ne 0 ] || [ $BLADE_STATUS -ne 0 ]; then exit 1 fi # Else success`! -echo "" exit 0 \ No newline at end of file From 8c32640f617e29caf169bf2e06532e645ce92383 Mon Sep 17 00:00:00 2001 From: "d.nakou@uu.nl" Date: Wed, 17 Dec 2025 12:15:15 +0100 Subject: [PATCH 5/6] include only files added or modified --- bin/git/hooks/pre-commit | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/git/hooks/pre-commit b/bin/git/hooks/pre-commit index e9c08c41..b3c9542a 100755 --- a/bin/git/hooks/pre-commit +++ b/bin/git/hooks/pre-commit @@ -26,8 +26,11 @@ echo "Checking PHP and Blade code style…" # Get relevant staged files -BLADE_FILES=$(git diff --cached --name-only -- '*.blade.php') -PHP_FILES=$(git diff --cached --name-only -- '*.php' ':!*.blade.php') +# --Cached for seeing the next commit +# --name-only for gathering only the path of the file and not the code. +# +BLADE_FILES=$(git diff --cached --diff-filter=AM --name-only -- '*.blade.php') +PHP_FILES=$(git diff --cached --diff-filter=AM --name-only -- '*.php' ':!*.blade.php') PHP_STATUS=0 BLADE_STATUS=0 From 2dfae15d086fd3ee4518ce3971677bacdabf0699 Mon Sep 17 00:00:00 2001 From: "d.nakou@uu.nl" Date: Wed, 17 Dec 2025 13:02:07 +0100 Subject: [PATCH 6/6] add a log level in prettier --- bin/git/hooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git/hooks/pre-commit b/bin/git/hooks/pre-commit index b3c9542a..04f56a94 100755 --- a/bin/git/hooks/pre-commit +++ b/bin/git/hooks/pre-commit @@ -57,7 +57,7 @@ fi if [ -z "$BLADE_FILES" ]; then echo "No staged Blade files to check." else - ./node_modules/.bin/prettier --write $BLADE_FILES & + ./node_modules/.bin/prettier --write $BLADE_FILES --log-level warn & spinner $! BLADE_STATUS=$?