Commit 80c627df authored by Edward Hervey's avatar Edward Hervey 🤘

pre-commit.hook: Use the file content from the index.

Issue reported by Jonas Holmberg on #gstreamer
parent 31a22da6
......@@ -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
$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.
$newfile 2>> /dev/null
diff -u -p "${file}" "${newfile}"
diff -u -p "${nf}" "${newfile}"
rm "${newfile}"
rm "${nf}"
if [ $r != 0 ] ; then
echo "Code style error in $file, please fix before commiting."
exit 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment