QGIS/scripts/verify_indentation.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
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]"
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
2020-05-11 15:35:52 +02:00
# echo "Commit range: $1"
2020-05-11 07:17:56 +02:00
FILES=$(git diff --diff-filter=AM --name-only $1 | tr '\n' ' ' )
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 09:16:34 +02:00
# echo "Checking $f"
case "$f" in
2024-11-20 11:28:19 +01:00
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip)
;;
*)
continue
;;
esac
# only run astyle on sipified directories, others are handled by clang-format (see .pre-commit-config.yaml)
2024-12-10 14:22:51 +01:00
if [[ $f =~ ^src/(core) ]]; then
m="$f.prepare"
cp "$f" "$m"
astyle.sh "$f"
if diff -u "$m" "$f" >>$ASTYLEDIFF; then
rm "$m"
else
echo "File $f is not styled properly."
fi
fi
2017-02-27 09:41:05 +01:00
done
if [ -s "$ASTYLEDIFF" ]; then
echo
echo "Required indentation updates:"
cat "$ASTYLEDIFF"
cat <<EOF
Tips to prevent and resolve:
2020-05-11 09:16:34 +02:00
* Install astyle to format C++ code
2016-03-06 22:21:43 +01:00
* Install autopep8 (>= 1.2.1) to format python code
2020-05-11 09:16:34 +02:00
* Use "scripts/astyle.sh file" to fix the now incorrectly formatted files
* 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
run it manually before each commit.
EOF
exit 1
fi