mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[git-tools] Improvements for the pre-commit hook
One major issue with the pre-hook so far was partially staged files, because it used filenames for php lint. These changes will make the hook read the file contents from the index instead. Great thanks to David Soria Parra.
This commit is contained in:
parent
6a9304021f
commit
ae48c8ee9e
1 changed files with 28 additions and 5 deletions
|
@ -25,12 +25,35 @@ fi
|
||||||
|
|
||||||
error=0
|
error=0
|
||||||
|
|
||||||
# get a list of staged .php files, omitting file removals
|
IFS=$'\n'
|
||||||
IFS=" "
|
# get a list of staged files
|
||||||
for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$')
|
for line in $(git diff-index --cached --full-index $against)
|
||||||
do
|
do
|
||||||
# hide output, but show errors
|
# split needed values
|
||||||
if ! $PHP_BIN -l "$file" >/dev/null
|
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)
|
||||||
|
git cat-file -p $sha | $PHP_BIN -l >/dev/null
|
||||||
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
error=1
|
error=1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue