Skip to content

Instantly share code, notes, and snippets.

@killerbees19
Created September 20, 2020 05:24
Show Gist options
  • Save killerbees19/73cee0053433c31b974d7cc7705bfb1c to your computer and use it in GitHub Desktop.
Save killerbees19/73cee0053433c31b974d7cc7705bfb1c to your computer and use it in GitHub Desktop.
Git pre-commit hook: PHP Lint Check
#!/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