Created
January 17, 2012 15:14
-
-
Save Ikke/1627000 to your computer and use it in GitHub Desktop.
Pre-commit hook for checking code style using PhpCheckStyle
This file contains hidden or 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/sh | |
echo "Checking codestyle" | |
echo | |
maxErrorLevel=0 | |
for file in $(git diff --cached --name-only --diff-filter=M -z HEAD) | |
do | |
echo "Checking $file" | |
echo "===============" | |
phpcheckstyle --src $file --format console --config tuna.cfg.xml | |
errorLevel=$? | |
echo "===============" | |
if [[ $errorLevel -gt $maxErrorLevel ]] | |
then | |
maxErrorLevel=$errorLevel | |
fi | |
done | |
if [[ $maxErrorLevel -gt 2 ]] | |
then | |
echo -e "\e[0;31mStyle errors, aborting \e[0m" | |
exit 1 | |
elif [[ $maxErrorLevel -gt 0 ]] | |
then | |
echo -e "\e[0;33mWarnings, proceeding \e[0m" | |
else | |
echo -e "\e[0;32mStyle ok, proceeding \e[0m" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment