2018-02-05 13:38:02 +01:00
|
|
|
#!/usr/bin/env bash
|
2015-12-03 20:49:14 +01:00
|
|
|
cd $(git rev-parse --show-toplevel)
|
|
|
|
|
|
|
|
export PATH=$PATH:$PWD/scripts
|
|
|
|
|
2020-05-11 07:17:56 +02:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "No commit range given. "
|
|
|
|
echo " Usage: ./scripts/verify_indentation [HEAD_REF]..[BASE_REF]"
|
2015-12-03 20:49:14 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! type -p astyle.sh >/dev/null; then
|
|
|
|
echo astyle.sh not found
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
ASTYLEDIFF=/tmp/astyle.diff
|
2018-06-21 12:29:46 +10:00
|
|
|
true > $ASTYLEDIFF
|
2015-12-03 20:49:14 +01:00
|
|
|
|
2015-12-25 04:28:33 +01:00
|
|
|
|
2020-05-11 07:17:56 +02:00
|
|
|
echo "Commit range: $1"
|
|
|
|
FILES=$(git diff --diff-filter=AM --name-only $1 | tr '\n' ' ' )
|
2015-12-03 20:49:14 +01:00
|
|
|
|
2017-02-27 09:41:05 +01:00
|
|
|
for f in $FILES; do
|
2015-12-07 10:07:24 +01:00
|
|
|
if ! [ -f "$f" ]; then
|
|
|
|
echo "$f was removed." >>/tmp/ctest-important.log
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2020-05-11 08:35:33 +02:00
|
|
|
echo "Checking $f"
|
2015-12-03 20:49:14 +01:00
|
|
|
case "$f" in
|
|
|
|
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-12-07 10:07:24 +01:00
|
|
|
m="$f.prepare"
|
2015-12-03 20:49:14 +01:00
|
|
|
cp "$f" "$m"
|
|
|
|
astyle.sh "$f"
|
|
|
|
if diff -u "$m" "$f" >>$ASTYLEDIFF; then
|
2015-12-07 10:07:24 +01:00
|
|
|
rm "$m"
|
2015-12-03 20:49:14 +01:00
|
|
|
else
|
|
|
|
echo "File $f needs indentation"
|
|
|
|
fi
|
2017-02-27 09:41:05 +01:00
|
|
|
done
|
2015-12-03 20:49:14 +01:00
|
|
|
|
|
|
|
if [ -s "$ASTYLEDIFF" ]; then
|
|
|
|
echo
|
|
|
|
echo "Required indentation updates:"
|
|
|
|
cat "$ASTYLEDIFF"
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
Tips to prevent and resolve:
|
2015-12-05 21:35:59 +01:00
|
|
|
* Enable WITH_ASTYLE in your cmake configuration to format C++ code
|
2016-03-06 22:21:43 +01:00
|
|
|
* Install autopep8 (>= 1.2.1) to format python code
|
2015-12-05 21:35:59 +01:00
|
|
|
* Use "scripts/astyle.sh file" to fix the now badly indented files
|
2020-04-14 09:39:56 +10:00
|
|
|
* Consider using scripts/prepare_commit.sh as pre-commit hook to avoid this
|
|
|
|
in the future (ln -s ../../scripts/prepare_commit.sh .git/hooks/pre-commit) or
|
2015-12-03 20:49:14 +01:00
|
|
|
run it manually before each commit.
|
|
|
|
EOF
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|