Created
September 7, 2018 03:58
-
-
Save zhouyl/005cdbc20e93521281e8e38ecc5276d3 to your computer and use it in GitHub Desktop.
phpline for git hooks
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/bash | |
# Author: Remigijus Jarmalavičius <[email protected]> | |
# Author: Vytautas Povilaitis <[email protected]> | |
# | |
# XDebug check added by William Clemens <http://github.com/wesclemens> | |
# Handle spaces in filenames Dave Barnwell <https://github.com/freshsauce> | |
ROOT_DIR="$(pwd)/" | |
LIST=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD) | |
ERRORS_BUFFER="" | |
for file in $LIST | |
do | |
EXTENSION=$(echo "$file" | grep ".php$") | |
if [ "$EXTENSION" != "" ]; then | |
ERRORS=$(php -l "$ROOT_DIR$file" 2>&1 | grep "Parse error") | |
if [ "$ERRORS" != "" ]; then | |
if [ "$ERRORS_BUFFER" != "" ]; then | |
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS" | |
else | |
ERRORS_BUFFER="$ERRORS" | |
fi | |
echo "Syntax errors found in file: $file " | |
fi | |
# Check for xdebug statments | |
# 检查xdebug语句会有误杀的现象, 这里屏蔽掉 | |
# ERRORS=$(grep -nH xdebug_ "$ROOT_DIR$file" | \ | |
# sed -e 's/^/Found XDebug Statment : /') | |
if [ "$ERRORS" != "" ]; then | |
if [ "$ERRORS_BUFFER" != "" ]; then | |
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS" | |
else | |
ERRORS_BUFFER="$ERRORS" | |
fi | |
fi | |
fi | |
done | |
if [ "$ERRORS_BUFFER" != "" ]; then | |
echo | |
echo "Found PHP parse errors: " | |
echo -e $ERRORS_BUFFER | |
echo | |
echo "PHP parse errors found. Fix errors and commit again." | |
exit 1 | |
else | |
echo "No PHP parse errors found. Committed successfully." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment