1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-29 20:29:22 +02:00

Merge branch 'feature/evil3/git-tools' into develop-olympus

* feature/evil3/git-tools:
  [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.
  [git-tools] Improvements for the pre-commit hook
  [git-tools] Improvements on prepare-commt-msg hook
  [git-tools] Some pre-commit enhancements, abolish tempfile
  [git-tools] use mktemp in pre-commit (thanks nn-)
  [git-tools] pre-commit hook for syntax checking
This commit is contained in:
Nils Adermann 2010-04-04 15:04:28 +02:00
commit fa9510be23
2 changed files with 88 additions and 6 deletions

72
git-tools/hooks/pre-commit Executable file

@ -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

@ -10,15 +10,25 @@
#
# ln -s ../../git-tools/hooks/prepare-commit-msg \\
# .git/hooks/prepare-commit-msg
#
# Make sure it is executable.
# strip off ref: refs/heads/
branch="$(cat $GIT_DIR/HEAD | sed 's/ref: refs\/heads\///g')"
# get branch name
branch="$(git symbolic-ref HEAD)"
# exit if no branch name is present
# (eg. detached HEAD)
if [ $? -ne 0 ]
then
exit
fi
# strip off refs/heads/
branch="$(echo "$branch" | sed "s/refs\/heads\///g")"
# add [branchname] to commit message
# * only run when normal commit is made (without -m or -F;
# not a merge, etc.)
# * also make sure the branch name begins with bug/ or feature/
if [ "$2" = "" ] && [ $(echo "$branch" | grep -e '^\(bug\|feature\)/') ]; then
echo "[$branch] $(cat $1)" > "$1"
if [ "$2" = "" ]
then
echo "[$branch] $(cat "$1")" > "$1"
fi