Skip to content

Instantly share code, notes, and snippets.

@wojtha
Created June 19, 2011 09:40
Show Gist options
  • Save wojtha/1034017 to your computer and use it in GitHub Desktop.
Save wojtha/1034017 to your computer and use it in GitHub Desktop.
Git pre-commit hook for PHP syntax validation using Msysgit Bash
#!/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