Skip to content

Instantly share code, notes, and snippets.

@rumkin
Last active December 14, 2015 21:18
Show Gist options
  • Save rumkin/5150026 to your computer and use it in GitHub Desktop.
Save rumkin/5150026 to your computer and use it in GitHub Desktop.
PHP syntax check on commit
#!/bin/bash
if [ ! -z $(tput colors) ]; then
bold=`tput bold`
normal=`tput sgr0`
fi
# Git info
commit=$(git log --max-count=1| head -n 1|cut -f 2 -d ' ');
status=0
for file in $(git diff-tree --no-commit-id --name-only -r $commit); do
php=$(echo $file | egrep "\.php$")
if [ -z $php ]; then continue; fi
error=$(php -l $file 2>&1 >/dev/null)
if [ ! -z "$error" ]; then
status=1
echo "${bold}${file}${normal}:" >&2
echo "$error" >&2
fi
done
exit $status
#!/bin/bash
set -e
bin/phpsyntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment