1#!/bin/sh 2# checking code style before commit 3 4ASTYLE=astyle 5ASTYLE_PARAMS="--indent=spaces=4 --convert-tabs --pad-oper --suffix=none" 6 7DOS2UNIX=dos2unix 8DOS2UNIX_PARAMS="-ascii --safe --keepdate --quiet" 9 10command -v $ASTYLE > /dev/null 2>&1 || echo "warning: $ASTYLE is not installed" 11command -v $DOS2UNIX > /dev/null 2>&1 || echo "warning: $DOS2UNIX is not installed" 12 13echo "---- checking code style (dos2unix / astyle)----" 14for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR | grep -E "\.c$|\.cpp$|\.h$|\.cl$|\.hpp$" ` ; do 15 $DOS2UNIX ${DOS2UNIX_PARAMS} ${file} 16 $ASTYLE ${ASTYLE_PARAMS} ${file} 17 ret=$? 18 if [ $ret != 0 ] ; then 19 echo "code style failed on $file" 20 exit 1 21 fi 22 git add $file 23done 24echo "---- checking code style done----" 25