aboutsummaryrefslogtreecommitdiffstats
path: root/git-tools/hooks/pre-commit
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2010-11-20 17:00:05 +0100
committerNils Adermann <naderman@naderman.de>2010-11-20 17:00:05 +0100
commit7f21a5f46156660d7ea6a4bdb59166ac553e2be8 (patch)
tree3963b4075f58c43ffc01fe290b04a800668bc53c /git-tools/hooks/pre-commit
parentc4e02a191628b4b9f7b6340f2876607663baeb5a (diff)
parentaf4c2a3eb15fc4318b23dcb7794c230cf3ec2a0f (diff)
downloadforums-7f21a5f46156660d7ea6a4bdb59166ac553e2be8.tar
forums-7f21a5f46156660d7ea6a4bdb59166ac553e2be8.tar.gz
forums-7f21a5f46156660d7ea6a4bdb59166ac553e2be8.tar.bz2
forums-7f21a5f46156660d7ea6a4bdb59166ac553e2be8.tar.xz
forums-7f21a5f46156660d7ea6a4bdb59166ac553e2be8.zip
Merge commit 'release-3.0.8'
* commit 'release-3.0.8': (393 commits) [prep-release-3.0.8] Incrementing version number to 3.0.8 and update changelog [ticket/9903] Script for detecting potentially malicious flash bbcodes [ticket/9904] Update WebPI Parameters.xml to work with WebMatrix. [ticket/9899] Change recaptcha theme from default to 'clean' in the ACP. [ticket/9509] Fix a typo and wrong period placement [ticket/9903] Fix XSS in BBcode-parser's Flash-BBcode. [develop-olympus] Updating changelog for last minute 3.0.8-RC1 fixes. [ticket/9140] Check current board version in incremental update packages [ticket/9891] Updater drops language-selection after database-update [develop-olympus] Updating changelog with latest changes for 3.0.8-RC1 [ticket/9884] Reduce queue interval to 60 seconds, email package size to 20 [ticket/9886] Update fails on PostgreSQL because of an error in _add_module [ticket/9888] Update fails when Bing [Bot] was already added to the users table [develop-olympus] Bumping version number for 3.0.8-RC1. [ticket/9885] Fix extension group name updater. Loop through all languages. [ticket/9847] Fix typo in search synonyms. Use british english for 'judgement'. [ticket/9883] Change an American English spelling to British English. [task/phing-build] Correct the path for update package patch files. [ticket/9880] Change "antibot" to "anti-spambot". [ticket/9696] Surpress is_dir() notice when using SQLite with open_basedir. ...
Diffstat (limited to 'git-tools/hooks/pre-commit')
-rwxr-xr-xgit-tools/hooks/pre-commit82
1 files changed, 82 insertions, 0 deletions
diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit
new file mode 100755
index 0000000000..4d03359773
--- /dev/null
+++ b/git-tools/hooks/pre-commit
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# A hook to disallow php syntax errors to be committed
+# by running php -l (lint) on them. It requires php-cli
+# to be installed.
+#
+# This is a pre-commit hook.
+#
+# To install this you can either copy or symlink it to
+# $GIT_DIR/hooks, example:
+#
+# ln -s ../../git-tools/hooks/pre-commit \\
+# .git/hooks/pre-commit
+
+# NOTE: this is run through /usr/bin/env
+PHP_BIN=php
+
+# necessary check for initial commit
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+error=0
+errors=""
+
+if ! which $PHP_BIN >/dev/null 2>&1
+then
+ echo "PHP Syntax check failed:"
+ echo "PHP binary does not exist or is not in path: $PHP_BIN"
+ exit 1
+fi
+
+# dash does not support $'\n':
+# http://forum.soft32.com/linux2/Bug-409179-DASH-Settings-IFS-work-properly-ftopict70039.html
+IFS='
+'
+# get a list of staged files
+for line in $(git diff-index --cached --full-index $against)
+do
+ # split needed values
+ sha=$(echo $line | cut -d' ' -f4)
+ temp=$(echo $line | cut -d' ' -f5)
+ status=$(echo $temp | cut -d' ' -f1)
+ filename=$(echo $temp | cut -d' ' -f2)
+
+ # file extension
+ ext=$(echo $filename | sed 's/^.*\.//')
+
+ # only check files with php extension
+ if [ $ext != "php" ]
+ then
+ continue
+ fi
+
+ # do not check deleted files
+ if [ $status = "D" ]
+ then
+ continue
+ fi
+
+ # check the staged file content for syntax errors
+ # using php -l (lint)
+ result=$(git cat-file -p $sha | /usr/bin/env $PHP_BIN -l 2>/dev/null)
+ if [ $? -ne 0 ]
+ then
+ error=1
+ # Swap back in correct filenames
+ errors=$(echo "$errors"; echo "$result" |sed -e "s@in - on@in $filename on@g")
+ fi
+done
+unset IFS
+
+if [ $error -eq 1 ]
+then
+ echo -e "PHP Syntax check failed:";
+ echo -e "$errors" | grep "^Parse error:"
+ exit 1
+fi