Created
May 11, 2012 05:55
-
-
Save yalab/2657810 to your computer and use it in GitHub Desktop.
PHP Syntax check before pre-commit hook of git
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="/usr/bin/php" | |
PWD=`pwd` | |
SYNTAXCHECK="/usr/bin/php -l" | |
GIT_ROOT=`pwd`/`git rev-parse --show-cdup` | |
MODIFIED_FILES=`git diff-index --cached HEAD | awk '{print $6}'` | |
ERRORS="" | |
for f in $MODIFIED_FILES;do | |
FNAME=${GIT_ROOT}${f} | |
if [ "php" != "${FNAME##*.}" ];then | |
continue | |
fi | |
RESULT=`$SYNTAXCHECK $FNAME` | |
if [ "$?" != "0" ];then | |
ERRORS="$ERRORS\n\n$RESULT" | |
fi | |
done | |
if [ -n "$ERRORS" ];then | |
echo "$ERRORS" | |
exit 1 | |
else | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment