diff options
| author | Nils Adermann <naderman@naderman.de> | 2010-04-04 15:04:56 +0200 |
|---|---|---|
| committer | Nils Adermann <naderman@naderman.de> | 2010-04-04 15:04:56 +0200 |
| commit | 382354925d59e3da12781f8877ab0a70d0c434d9 (patch) | |
| tree | a78840711da6763ee1cdba13357f728f71b4e658 /git-tools/hooks/pre-commit | |
| parent | d702dba75e14a909c165c7ca7a6a87207dcadaaf (diff) | |
| parent | fa9510be23e76b8729e2ea16fc0e8403c7a3643c (diff) | |
| download | forums-382354925d59e3da12781f8877ab0a70d0c434d9.tar forums-382354925d59e3da12781f8877ab0a70d0c434d9.tar.gz forums-382354925d59e3da12781f8877ab0a70d0c434d9.tar.bz2 forums-382354925d59e3da12781f8877ab0a70d0c434d9.tar.xz forums-382354925d59e3da12781f8877ab0a70d0c434d9.zip | |
Merge branch 'develop-olympus' into develop
* develop-olympus: (26 commits)
[git-tools] add note about PHP_BIN using env
[git-tools] do not display stderr
[git-tools] Prepend the branch to the commit message for all branches.
[git-tools] Use env to find the correct paths to binaries.
[git-tools] Display what parse errors were found.
[git-tools] This script requires bash to run, so point directly to bash.
[feature/dbal-tests] Remove hardcoded 'mysql' from PDO DSN in DBAL test.
[feature/dbal-tests] Fix mysql (not mysqli) dbal test.
[feature/dbal-tests] Only output the missing config error message once.
[feature/dbal-tests] Make the PDO prefix depend on the dbms.
[feature/dbal-tests] Fix whitespace and line endings.
[bug/9108] Fix table binding issues with PostgreSQL in board-wide feed. (Old Bug #58425)
[bug/59425] Correctly check for double inclusion in captcha garbage collection
[bug/58465] The redirect hidden field is now XHTML conform
[feature/dbal-tests] Make some tests for build_array_data on SELECT
[feature/dbal-tests] Make some tests for return_on_error on SELECT-queries
[feature/dbal-tests] Tests for $db->sql_query_limit()
[feature/dbal-tests] Load phpbb-schema after creating the connection to the database
[feature/dbal-tests] Added tests for dbal fetchrow and fetchfield.
[feature/dbal-tests] Added database test & refactored test framework
...
Diffstat (limited to 'git-tools/hooks/pre-commit')
| -rwxr-xr-x | git-tools/hooks/pre-commit | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit new file mode 100755 index 0000000000..23ab8d6cdb --- /dev/null +++ b/git-tools/hooks/pre-commit @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# +# 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="" + +IFS=$'\n' +# 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+=${result//in - on/"$filename"} + fi +done +unset IFS + +if [ $error -eq 1 ] +then + echo -e "PHP Syntax check failed:"; + echo -e "$errors" | grep "^Parse error:" + exit 1 +fi |
