3 # Check that the code follows a consistant code style
6 # Check for existence of astyle, and error out if not present.
7 if ! builtin type -P astyle
; then
8 echo "PyGI git pre-commit hook:"
9 echo "Did not find astyle, please install it before continuing."
13 ASTYLE_PARAMETERS
="-p -d -c -S -U -M60"
15 echo "--Checking style--"
16 for file in `git-diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
17 # nf is the temporary checkout. This makes sure we check against the
18 # revision in the index (and not the checked out version).
19 nf
=`git checkout-index --temp ${file} | cut -f 1`
20 newfile
=`mktemp /tmp/${nf}.XXXXXX` ||
exit 1
21 astyle
${ASTYLE_PARAMETERS} < $nf > $newfile 2>> /dev
/null
22 diff -u -p "${nf}" "${newfile}"
27 echo "================================================================================================="
28 echo " Code style error in: $file "
30 echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
31 echo " If the whole file is to be committed, this should work (run from the top-level directory): "
33 echo " astyle ${ASTYLE_PARAMETERS} $file; git add $file; git commit"
35 echo "================================================================================================="
39 echo "--Checking style pass--"