2 cd $(git rev-parse --show-toplevel)
4 export PATH=$PATH:$PWD/scripts
6 if [ -z "$TRAVIS_COMMIT_RANGE" -a -z "$GITHUB_SHA" ]; then
7 echo "No commit range given"
11 if ! type -p astyle.sh >/dev/null; then
12 echo astyle.sh not found
18 ASTYLEDIFF=/tmp/astyle.diff
21 if [ ! -z $GITHUB_BASE_REF ] && [ ! -z $GITHUB_HEAD_REF ]; then
23 echo "GitHub PR COMMIT RANGE: ${GITHUB_BASE_REF}..${GITHUB_HEAD_REF}"
24 git branch tmp_${GITHUB_BASE_REF} origin/${GITHUB_BASE_REF}
25 BASE_SHA1=$(git rev-parse tmp_${GITHUB_BASE_REF})
26 FILES=$(git diff --diff-filter=AMR --name-only ${BASE_SHA1}..${GITHUB_SHA} | tr '\n' ' ' )
27 elif [ ! -z $GITHUB_SHA ]; then
28 echo "GitHub push COMMIT $GITHUB_SHA"
29 FILES=$(git diff --diff-filter=AMR --name-only ${GITHUB_SHA}~1..${GITHUB_SHA} | tr '\n' ' ' )
30 elif [ ! -z $TRAVIS_PULL_REQUEST_BRANCH ]; then
31 # if on a PR, just analyse the changed files
32 echo "TRAVIS PR BRANCH: $TRAVIS_PULL_REQUEST_BRANCH"
33 FILES=$(git diff --diff-filter=AMR --name-only $(git merge-base HEAD master) | tr '\n' ' ' )
34 elif [ ! -z $TRAVIS_COMMIT_RANGE ]; then
35 echo "TRAVIS COMMIT RANGE: $TRAVIS_COMMIT_RANGE"
36 FILES=$(git diff --diff-filter=AMR --name-only ${TRAVIS_COMMIT_RANGE/.../..} | tr '\n' ' ' )
40 if ! [ -f "$f" ]; then
41 echo "$f was removed." >>/tmp/ctest-important.log
45 echo "Checking $f" >>/tmp/ctest-important.log
52 *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
63 if diff -u "$m" "$f" >>$ASTYLEDIFF; then
66 echo "File $f needs indentation"
70 if [ -s "$ASTYLEDIFF" ]; then
72 echo "Required indentation updates:"
77 Tips to prevent and resolve:
78 * Enable WITH_ASTYLE in your cmake configuration to format C++ code
79 * Install autopep8 (>= 1.2.1) to format python code
80 * Use "scripts/astyle.sh file" to fix the now badly indented files
81 * Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this
82 in the future (ln -s scripts/prepare-commit.sh .git/hooks/pre-commit) or
83 run it manually before each commit.