summaryrefslogtreecommitdiff
path: root/hooks/pre-commit.hook
blob: a1d75021a743542ff1131bbc3e49be78019365d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
#
# Check that the code follows a consistant code style
#
 
# FIXME : Add a check for existence of indent, and return 0 if not present

INDENT_PARAMETERS="--braces-on-if-line \
	--case-brace-indentation0 \
	--case-indentation2 \
	--braces-after-struct-decl-line \
	--line-length80 \
	--no-tabs \
	--cuddle-else \
	--dont-line-up-parentheses \
	--continuation-indentation4 \
	--honour-newlines \
	--tab-size8 \
	--indent-level2"
 
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
    indent ${INDENT_PARAMETERS} \
	$file -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}"
    r=$?
    rm "${newfile}"
    if [ $r != 0 ] ; then
echo "Code style error in $file, please fix before commiting."
        exit 1
    fi
done
echo "--Checking style pass--"