-
-
Save adirkuhn/9a2228da412a27225d00ae6ca20ebe96 to your computer and use it in GitHub Desktop.
A *really* simple git pre-commit-hook that lints all staged PHP files.
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 | |
stagedFiles=$(git diff-index --cached HEAD | grep ".php" | grep "^:" | cut -f2); | |
phpLintErrors=0 | |
echo "PHP will now lint all the php staged files..." | |
echo "" | |
for file in $stagedFiles | |
do | |
echo "PHP is linting $file..."; | |
echo "" | |
php -l $file | |
RETVAL=$? | |
if [[ $RETVAL != 0 ]] | |
then | |
phpLintErrors=1 | |
fi | |
echo "" | |
done | |
if [[ $phpLintErrors == 1 ]] | |
then | |
echo "" | |
echo "-----" | |
echo "Please, correct the errors above. Commit aborted." | |
echo "-----" | |
exit 1 | |
else | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment