Skip to content

Instantly share code, notes, and snippets.

@jiskanulo
Last active August 29, 2015 14:17
Show Gist options
  • Save jiskanulo/e3fcfb0c1037491b2c19 to your computer and use it in GitHub Desktop.
Save jiskanulo/e3fcfb0c1037491b2c19 to your computer and use it in GitHub Desktop.
Git pre-commit hook: php syntax check
#!/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