#/bin/sh

# svncheckphp.sh 0.2
#
# Copyright 2004-2005 Turadg Aleahmad
# http://php-mode.sourceforge.net/
#
# Checks syntax of PHP files on Subversion commit and aborts on error
#
# To use, put this somewhere like /usr/local/bin and set permissions
# to executable (eg. 755)
#
# Then add a line like this to your Subversion hooks/pre-commit file:
#   /path/to/svncheckphp.sh $1 $2 || exit 1
#
# If php isn't in your command path, set PHPCMD below.
# If your PHP files end in other extensions, add cases for them.
#

# set this to absolute path if necessary
PHPCMD=php

svnlook changed -t "$2" "$1" |cut -c 5- | while read FILEPATH ; do
  # uncomment this line to parse only PHP file
  # requires Bash v3.0
  if [[ ! $FILEPATH =~ '\.php' ]]; then continue; fi
  if svnlook cat -t "$2" "$1" $FILEPATH | php -l; then continue; else
    echo "PHP syntax error in $FILEPATH" >&2
    exit 1
  fi
done
