#!/bin/bash # Support old version of astyle 2.04 less -f `which astyle` | grep 2.04 BUG=$? ASTYLE=$(which astyle) OPTIONS="--options=./.astylerc" RETURN=0 FILES=`git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h|hpp)$"` for FILE in $FILES; do if [ $BUG -ne 0 ]; then $ASTYLE $OPTIONS < $FILE | cmp -s $FILE - else $ASTYLE $OPTIONS < $FILE | head -c -1 | cmp -s $FILE - fi if [ $? -ne 0 ]; then echo "$?" >&2 echo "[!] $FILE does not respect the agreed coding style." >&2 RETURN=1 fi done if [ $RETURN -eq 1 ]; then echo "" >&2 echo "Make sure you have run astyle with options:" >&2 echo "$OPTIONS" >&2 echo "on the file(s)" >&2 fi exit $RETURN