1*4882a593Smuzhiyun#!/bin/sh 2*4882a593Smuzhiyun 3*4882a593Smuzhiyunecho "[git-hook]: before commit, format code use astyle ..." 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunASTYLE_PARAMETERS="--style=linux \ 6*4882a593Smuzhiyun --indent=spaces=4 \ 7*4882a593Smuzhiyun --indent-labels \ 8*4882a593Smuzhiyun --min-conditional-indent=0 \ 9*4882a593Smuzhiyun --max-instatement-indent=80 \ 10*4882a593Smuzhiyun --pad-oper \ 11*4882a593Smuzhiyun --pad-header \ 12*4882a593Smuzhiyun --keep-one-line-blocks \ 13*4882a593Smuzhiyun --keep-one-line-statements \ 14*4882a593Smuzhiyun --convert-tabs\ 15*4882a593Smuzhiyun --suffix=none" 16*4882a593Smuzhiyun 17*4882a593Smuzhiyunif ! astyle --version 2>/dev/null; then 18*4882a593Smuzhiyun echo "astyle is missing, please install it: sudo apt-get install astyle" 19*4882a593Smuzhiyun exit 1 20*4882a593Smuzhiyunfi 21*4882a593Smuzhiyun 22*4882a593Smuzhiyunformat_file=$(find . -type f | grep -E "\.c$|\.h$") 23*4882a593Smuzhiyunastyle --quiet $ASTYLE_PARAMETERS $format_file 24*4882a593Smuzhiyun 25*4882a593Smuzhiyunif git status -s | grep -q "^ M "; then 26*4882a593Smuzhiyun echo "[git-hook]: code changed after formating, please commit again." 27*4882a593Smuzhiyun git status 28*4882a593Smuzhiyun echo "if you have completed all file formatting but there are still files in the workspace " 29*4882a593Smuzhiyun echo "use --no-verify to skip hook" 30*4882a593Smuzhiyun exit 1 31*4882a593Smuzhiyunfi 32*4882a593Smuzhiyun 33*4882a593Smuzhiyunecho "[git-hook]: nothing change after formating, commit continues."