From 0c21f6caa3cbb993ab44f79163a83faba1050f40 Mon Sep 17 00:00:00 2001 From: Jordan Wamser Date: Wed, 17 Jul 2024 09:14:38 -0500 Subject: [PATCH] update precommit hook --- templates/pre-commit | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/templates/pre-commit b/templates/pre-commit index f858db2..6c0db54 100644 --- a/templates/pre-commit +++ b/templates/pre-commit @@ -3,5 +3,22 @@ export PATH=$PATH:/usr/local/bin:/opt/homebrew/bin set -e + +# Initial cache of files +INIT_FILES=$(git diff --name-only --cached) + +# Run Make file make precommit -git add . + +# Get the list of modified files after running php-cs-fixer +MODIFIED_FILES=$(git diff --name-only --cached) + +# Compare the new list to the original list and add the matching files to the staging area +for file in $MODIFIED_FILES; do + for init_file in $INIT_FILES; do + if [ "$file" = "$init_file" ] && [ -e "$file" ]; then + git add "$file" + break + fi + done +done \ No newline at end of file