OSDN Git Service

Add pre-commit hook
[android-x86/hardware-intel-common-vaapi.git] / hooks / pre-commit.hook
1 #!/bin/sh
2 #
3 # Use astyle to check the coding style
4 #
5
6 ASTYLE=astyle
7 ASTYLE_PARAMS="--style=linux -cnpUH -s4 -M120"
8
9 if [ -z "`which $ASTYLE 2> /dev/null`" ]; then
10     echo "git pre-commit hook:"
11     echo "Don't find $ASTYLE, please install $ASTYLE before committing the changes"
12     exit 1
13 fi
14
15 echo "Checking coding style..."
16 echo ""
17 for file in `git diff-index --cached --name-only --diff-filter=ACMR HEAD src/ | grep "\.[ch]$" 2> /dev/null`; do
18     tmp0file=`git checkout-index --temp ${file} | cut -f 1`
19     tmp1file=`mktemp /tmp/${tmp0file}.XXX` || exit 1
20     $ASTYLE $ASTYLE_PARAMS < ${tmp0file} > ${tmp1file} 2> /dev/null
21     diff -up "${tmp0file}" "${tmp1file}"
22     ret=$?
23     rm -f "${tmp0file}" "${tmp1file}"
24     if [ $ret != 0 ]; then
25 echo ""
26 echo "**************************************************************************"
27 echo " Coding style error in $file"
28 echo ""
29 echo " Please fix the coding style before committing. You may run the command"
30 echo " below to fix the coding style from the top-level directory"
31 echo ""
32 echo " $ASTYLE $ASTYLE_PARAMS $file"
33 echo "**************************************************************************"
34         exit 1
35     fi
36 done
37 echo "PASS!!!"