Merge pull request #4391 from seamuslee001/master
[civicrm-core.git] / tools / scripts / git / pre-commit
CommitLineData
87caf473
TO
1#!/bin/bash
2
3# Note: This shell script should be designed and tested for cross-platform use
4
5# URL: https://github.com/totten/git-php-syntax-checker/
31037a42 6# Author: Remigijus Jarmalavičius <remigijus@jarmalavicius.lt>
87caf473
TO
7# Author: Vytautas Povilaitis <php-checker@vytux.lt>
8# License: GPLv3
9
10ROOT_DIR="$(pwd)/"
11LIST=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD)
12ERRORS_BUFFER=""
13for file in $LIST
14do
15 EXTENSION=$(echo "$file" | grep -E ".php$|.module$|.inc$|.install$")
16 if [ "$EXTENSION" != "" ]; then
17 ERRORS=$(php -l $ROOT_DIR$file 2>&1 | grep "Parse error")
18 if [ "$ERRORS" != "" ]; then
19 if [ "$ERRORS_BUFFER" != "" ]; then
20 ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
21 else
22 ERRORS_BUFFER="$ERRORS"
23 fi
24 echo "Syntax errors found in file: $file "
25 fi
26 fi
27done
28if [ "$ERRORS_BUFFER" != "" ]; then
31037a42 29 echo
87caf473
TO
30 echo "These errors were found in try-to-commit files: "
31 echo -e $ERRORS_BUFFER
31037a42 32 echo
87caf473
TO
33 echo "Can't commit, fix errors first."
34 exit 1
35else
36 echo "Commited successfully."
37fi