Skip to content

Instantly share code, notes, and snippets.

@vkdimitrov
Last active December 19, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkdimitrov/5969672 to your computer and use it in GitHub Desktop.
Save vkdimitrov/5969672 to your computer and use it in GitHub Desktop.
pre-receive hook that check php syntax
#!/bin/bash
COMMAND="php -l "
TEMPDIR=`mktemp -d`
RED="\e[1;31m"
NONE="\e[m"
while read oldrev newrev refname; do
files=`git diff --name-only ${oldrev} ${newrev}`
for file in ${files}; do
object=`git ls-tree --full-name -r ${newrev} | egrep "(\s)${file}\$" | awk '{ print $3 }'`
if [ -z ${object} ]; then continue; fi
mkdir -p "${TEMPDIR}/`dirname ${file}`" &> /dev/null
git cat-file blob ${object} > ${TEMPDIR}/${file}
done;
done;
cd ${TEMPDIR}
for i in *
do
echo -e "${RED}"
${COMMAND} $i
STATUS=$?
echo -e "${NONE}"
if [ $STATUS -ne 0 ]
then
exit ${STATUS}
fi
done;
rm -rf ${TEMPDIR} &> /dev/null
exit ${STATUS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment