I usually use Phing to manage my lint and unit tests, but I’m dealing with a rather large (existing) project, and Phing is taking too long to lint all the files in the project. I noticed that most of the suggested “only modified files” scripts used PHP, which is fine I guess but it seems like such a waste when a simple Bash script in .git/hooks/pre-commit can suffice:
#!/usr/bin/env bash
if [ "$(id -u)" == "0" ]; then
echo "You cannot commit as root" 1>&2
exit 1
fi
FILES=`git diff --cached --name-status --diff-filter=ACM | awk '{ if ($1 != "D") print $2 }' | grep -e \.php$`
for x in $FILES
do
CMD="php -l $x"
echo $CMD
RES=`$CMD`
if [ $? -gt 0 ]; then
echo $RES
fi
done