uncrustify_precommit (651B)
1 #!/bin/sh 2 3 # use as .git/hooks/pre-commit 4 5 exec 1>&2 6 7 RET=0 8 changed=$(git diff --cached --name-only) 9 crustified="" 10 11 for f in $changed; 12 do 13 if echo $f | grep \\.[c,h]\$ > /dev/null 14 then 15 # compare result of uncrustify with changes 16 # 17 # only change any of the invocations here if 18 # they are portable across all cmp and shell 19 # implementations ! 20 uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f - 21 if test $? = 1 ; 22 then 23 crustified=" $crustified $f" 24 RET=1 25 fi 26 fi 27 done 28 29 if [ $RET = 1 ]; 30 then 31 echo "Run" 32 echo "uncrustify --replace -c uncrustify.cfg ${crustified}" 33 echo "before committing." 34 fi 35 exit $RET