Created
September 20, 2020 05:24
-
-
Save killerbees19/73cee0053433c31b974d7cc7705bfb1c to your computer and use it in GitHub Desktop.
Git pre-commit hook: PHP Lint Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git diff --cached --name-status --diff-filter=d \ | |
| awk '{print $(NF)}' | grep -Ei '\.(php)$' \ | |
| while IFS= read -r file | |
do | |
msg=$(git show ":$file" | php -l 2>&1) | |
# shellcheck disable=SC2181 | |
if [ $? -ne 0 ] | |
then | |
printf '\n PHP LINT [%s]\n git show %q\n\n' "$file" ":$file" | |
printf '%s\n' "$msg" | head -n 1 | |
printf '\n \e[5;41mPre-commit error found. Won'\''t commit!\e[m' | |
printf '\n Fix this error before trying again...' | |
printf '\n Use --no-verify in case of urgency.\n\n' | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment