|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +cd $(git rev-parse --show-toplevel) |
| 4 | + |
| 5 | +export PATH=$PATH:$PWD/scripts |
| 6 | + |
| 7 | +if [ -z "$TRAVIS_COMMIT_RANGE" ]; then |
| 8 | + echo "No commit range given" |
| 9 | + exit 0 |
| 10 | +fi |
| 11 | + |
| 12 | +TRAVIS_COMMIT_RANGE=${TRAVIS_COMMIT_RANGE/.../..} |
| 13 | + |
| 14 | +if ! type -p astyle.sh >/dev/null; then |
| 15 | + echo astyle.sh not found |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +set -e |
| 20 | + |
| 21 | +ASTYLEDIFF=/tmp/astyle.diff |
| 22 | +>$ASTYLEDIFF |
| 23 | + |
| 24 | +echo "Checking indentation in $TRAVIS_COMMIT_RANGE" |
| 25 | +echo "Checking indentation in $TRAVIS_COMMIT_RANGE" >>/tmp/ctest-important.log |
| 26 | +git log $TRAVIS_COMMIT_RANGE >>/tmp/ctest-important.log 2>&1 |
| 27 | +git diff --name-only $TRAVIS_COMMIT_RANGE >>/tmp/ctest-important.log 2>&1 |
| 28 | + |
| 29 | +git diff --name-only $TRAVIS_COMMIT_RANGE | while read f |
| 30 | +do |
| 31 | + echo "Checking $f" >>/tmp/ctest-important.log |
| 32 | + case "$f" in |
| 33 | + src/core/gps/qextserialport/*|src/plugins/dxf2shp_converter/dxflib/src/*|src/plugins/globe/osgEarthQt/*|src/plugins/globe/osgEarthUtil/*) |
| 34 | + echo $f skipped |
| 35 | + continue |
| 36 | + ;; |
| 37 | + |
| 38 | + *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py) |
| 39 | + ;; |
| 40 | + |
| 41 | + *) |
| 42 | + continue |
| 43 | + ;; |
| 44 | + esac |
| 45 | + |
| 46 | + m=$f.prepare |
| 47 | + cp "$f" "$m" |
| 48 | + astyle.sh "$f" |
| 49 | + if diff -u "$m" "$f" >>$ASTYLEDIFF; then |
| 50 | + rm $m |
| 51 | + else |
| 52 | + echo "File $f needs indentation" |
| 53 | + fi |
| 54 | +done |
| 55 | + |
| 56 | +if [ -s "$ASTYLEDIFF" ]; then |
| 57 | + echo |
| 58 | + echo "Required indentation updates:" |
| 59 | + cat "$ASTYLEDIFF" |
| 60 | + |
| 61 | + cat <<EOF |
| 62 | +
|
| 63 | +Tips to prevent and resolve: |
| 64 | +* Enable WITH_ASTYLE in your cmake configuration |
| 65 | +* Use scripts/astyle.sh file to fix the now badly indented files |
| 66 | +* Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this |
| 67 | + in the future (ln -s scripts/prepare-commit.sh .git/hooks/pre-commit) or |
| 68 | + run it manually before each commit. |
| 69 | +EOF |
| 70 | + |
| 71 | + exit 1 |
| 72 | +fi |
0 commit comments