Skip to content

Instantly share code, notes, and snippets.

@Ikke
Created January 17, 2012 15:14
Show Gist options
  • Save Ikke/1627000 to your computer and use it in GitHub Desktop.
Save Ikke/1627000 to your computer and use it in GitHub Desktop.
Pre-commit hook for checking code style using PhpCheckStyle
#!/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