Skip to content

Instantly share code, notes, and snippets.

@sylr
Created March 29, 2010 12:46
Show Gist options
  • Select an option

  • Save sylr/347805 to your computer and use it in GitHub Desktop.

Select an option

Save sylr/347805 to your computer and use it in GitHub Desktop.
pre-commit hook script for PHP5 projects
#!/bin/sh
#
# author : Sylvain Rabot <sylvain@abstraction.fr>
# date : 29/03/2010
#
# pre-commit hook script for PHP5 projects
#
# check PHP5 synthax of each modified files
# check tab/space indentation errors
###################### PHP SYNTHAX ######################
pass=1
for file in `git diff --cached --name-only | grep ".phps\?5\?$" --colour=never`
do
if [ ! -e $file ]; then
# file removed
continue;
fi
# checking synthax
/usr/bin/env php5 -l $file > /dev/null 2>&1;
exit=$?
if [ $exit -ne 0 ]; then
if [ $pass -eq 1 ]; then
pass=0
echo
echo "php synthax errors found :"
echo
fi
echo -n " - "; /usr/bin/env php5 -l $file 1> /dev/null
fi
done
if [ $pass -ne 1 ]; then
echo
exit 12
fi
###################### DIFF CHECK ######################
git diff --cached --check --no-color > /dev/null 2>&1
exit=$?
if [ $exit -ne 0 ]; then
echo
echo "indentation problems found :"
echo
git diff --cached --check
echo
exit 13
fi
###################### EXIT CODE ######################
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment