diff options
author | Edward Hervey <bilboed@bilboed.com> | 2009-02-09 11:57:16 +0100 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2009-02-09 11:57:16 +0100 |
commit | 80c627dfabb45c3f40727dce755c81bed1e38e3d (patch) | |
tree | 6f1ae5ee8203739d54f5c4ab937605336faeadbd /hooks | |
parent | 31a22da6ef102a7d25575faf88195a2188c39955 (diff) |
pre-commit.hook: Use the file content from the index.
Issue reported by Jonas Holmberg on #gstreamer
Diffstat (limited to 'hooks')
-rwxr-xr-x | hooks/pre-commit.hook | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/hooks/pre-commit.hook b/hooks/pre-commit.hook index a1d7502..a896fa4 100755 --- a/hooks/pre-commit.hook +++ b/hooks/pre-commit.hook @@ -20,18 +20,20 @@ INDENT_PARAMETERS="--braces-on-if-line \ echo "--Checking style--" for file in `git-diff-index --cached --name-only HEAD | grep "\.c$"` ; do - test -f ${file} || continue - tempfoo=`basename $0` - newfile=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1 + # nf is the temporary checkout. This makes sure we check against the + # revision in the index (and not the checked out version). + nf=`git checkout-index --temp ${file} | cut -f 1` + newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1 indent ${INDENT_PARAMETERS} \ - $file -o $newfile 2>> /dev/null + $nf -o $newfile 2>> /dev/null # FIXME: Call indent twice as it tends to do line-breaks # different for every second call. indent ${INDENT_PARAMETERS} \ $newfile 2>> /dev/null - diff -u -p "${file}" "${newfile}" + diff -u -p "${nf}" "${newfile}" r=$? rm "${newfile}" + rm "${nf}" if [ $r != 0 ] ; then echo "Code style error in $file, please fix before commiting." exit 1 |