aboutsummaryrefslogtreecommitdiffstats
path: root/git-tools
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2010-03-17 21:04:54 +0100
committerIgor Wiedler <igor@wiedler.ch>2010-03-17 23:07:57 +0100
commitae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4 (patch)
tree52db7ad2e47a5fdcdce544bd4534604675e07cec /git-tools
parent6a9304021f41cd8319ccb009bb24792ffc5438bc (diff)
downloadforums-ae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4.tar
forums-ae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4.tar.gz
forums-ae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4.tar.bz2
forums-ae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4.tar.xz
forums-ae48c8ee9ecf7866e4fe1ca4d3390d69a1adc2b4.zip
[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.
Diffstat (limited to 'git-tools')
-rwxr-xr-xgit-tools/hooks/pre-commit33
1 files changed, 28 insertions, 5 deletions
diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit
index 6129470196..1c67a0f3e3 100755
--- a/git-tools/hooks/pre-commit
+++ b/git-tools/hooks/pre-commit
@@ -25,12 +25,35 @@ fi
error=0
-# get a list of staged .php files, omitting file removals
-IFS=" "
-for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$')
+IFS=$'\n'
+# get a list of staged files
+for line in $(git diff-index --cached --full-index $against)
do
- # hide output, but show errors
- if ! $PHP_BIN -l "$file" >/dev/null
+ # 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)
+ git cat-file -p $sha | $PHP_BIN -l >/dev/null
+ if [ $? -ne 0 ]
then
error=1
fi