File: pre-commit

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (42 lines) | stat: -rwxr-xr-x 1,523 bytes parent folder | download | duplicates (11)
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
41
42
#!/bin/bash
#
# Check that the code follows a consistant code style
#

# Check for existence of astyle, and error out if not present.
if [ ! -x "$(which astyle)" ]; then
	echo "git pre-commit hook:"
	echo "Did not find astyle, please install it before continuing."
	exit 1
fi

ASTYLE_PARAMETERS="--style=linux --indent=force-tab"
FILE_PATTERN="\.(c|cpp|h)$"
IGNORE_PATTERN="^src/lib/"

echo "--Checking style--"
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| egrep $FILE_PATTERN| egrep -v $IGNORE_PATTERN` ; do
	# 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
	astyle ${ASTYLE_PARAMETERS} < $nf > $newfile 2>> /dev/null
	diff -u -p "${nf}" "${newfile}"
	r=$?
	rm "${newfile}"
	rm "${nf}"
	if [ $r != 0 ] ; then
		echo "================================================================================================="
		echo " Code style error in: $file "
		echo " "
		echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
		echo " If the whole file is to be committed, this should work (run from the top-level directory): "
		echo " "
		echo " astyle ${ASTYLE_PARAMETERS} $file; git add $file; git commit"
		echo " "
		echo "================================================================================================="
	exit 1
	fi
done
echo "--Checking style pass--"