summaryrefslogblamecommitdiffstats
path: root/scripts/astyle-check.sh
blob: 1e382c7fd3c05d07919b701e8fe6c3eae35c9d98 (plain) (tree)































                                                                                     
#!/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