Last active
August 29, 2015 14:17
-
-
Save jiskanulo/e3fcfb0c1037491b2c19 to your computer and use it in GitHub Desktop.
Git pre-commit hook: php syntax check
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 | |
CURRENT_DIR="$(pwd)" | |
HAS_ERROR="" | |
for file in $(git status -s | grep -E '^[AMU].*\.php$' | awk '{print $2}' | sort | uniq); do | |
if [ "$(php -l $(pwd)/$file 2>&1 | grep 'Parse error')" != "" ]; then | |
HAS_ERROR="1" | |
echo "Syntax errors found: $file" >&2 | |
fi | |
if [ "$(grep 'var_dump(' $(pwd)/$file 2>&1)" != "" ]; then | |
HAS_ERROR="1" | |
echo "var_dump() found: $file" >&2 | |
fi | |
done | |
if [ "$HAS_ERROR" != "" ]; then | |
echo "Can't commit, fix errors first." >&2 | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment