Created
June 19, 2011 09:40
-
-
Save wojtha/1034017 to your computer and use it in GitHub Desktop.
Git pre-commit hook for PHP syntax validation using Msysgit Bash
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/sh | |
php_syntax_check() | |
{ | |
retval=0 | |
for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\.(php|engine|theme|install|inc|module|test)$'); do | |
if [ -f $i ]; then | |
output=$(/c/progra~2/zend/zendserver/bin/php.exe -l $i) | |
if [ "$output" == "No syntax errors detected in $i" ]; | |
then | |
echo "PHP syntax check for $i: OK" | |
else | |
echo "==============================================================================" | |
echo "Unstaging $i for the commit due to PHP parse errors:" | |
echo "$output" | |
git reset -q HEAD $i | |
retval=1 | |
fi | |
fi | |
done | |
if [ $retval -gt 0 ]; then | |
exit $retval | |
fi | |
} | |
php_syntax_check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment