From 692748a07684cf6caf67fa736db853781c58842f Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Thu, 29 Sep 2016 15:48:49 +0200 Subject: added a pre-commit hook for astyle. --- scripts/astyle-check.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 scripts/astyle-check.sh (limited to 'scripts') diff --git a/scripts/astyle-check.sh b/scripts/astyle-check.sh new file mode 100755 index 0000000..1e382c7 --- /dev/null +++ b/scripts/astyle-check.sh @@ -0,0 +1,32 @@ +#!/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 -- cgit v1.2.3-55-g7522