Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 # checking code style before commit
      3 
      4 ASTYLE=astyle
      5 ASTYLE_PARAMS="--indent=spaces=4 --convert-tabs --pad-oper --suffix=none"
      6 
      7 DOS2UNIX=dos2unix
      8 DOS2UNIX_PARAMS="-ascii --safe --keepdate --quiet"
      9 
     10 command -v $ASTYLE > /dev/null 2>&1 || echo "warning: $ASTYLE is not installed"
     11 command -v $DOS2UNIX > /dev/null 2>&1 || echo "warning: $DOS2UNIX is not installed"
     12 
     13 echo "---- checking code style (dos2unix / astyle)----"
     14 for 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
     23 done
     24 echo "---- checking code style done----"
     25