#!/bin/bash
# Lint php files


if git-rev-parse --verify HEAD 2>/dev/null
then
    git-diff-index --name-only --cached HEAD --
else
	# NEEDSWORK: we should produce a diff with an empty tree here
	# if we want to do the same verification for the initial import.
    :
fi|
python -c '
import sys
import os
import subprocess
import commands


lines = sys.stdin.readlines()
BAD = 0
def check_file(file):
    res = 666 
    # stupid php & sigfault
    while res not in [0, 255]:
        res = subprocess.call(["php", "-l", file ])
    if res != 0:
        globals()["BAD"] = 1

for line in lines:
    line = line[:-1]
    if line.endswith(".php") and os.path.isfile(line):
        check_file(line)

sys.exit(BAD)
'

