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 ${GITHUB_BASE_REF} origin/${GITHUB_BASE_REF}
25 git branch ${GITHUB_HEAD_REF} origin/${GITHUB_HEAD_REF}
26 BASE_SHA1=$(git rev-parse ${GITHUB_BASE_REF})
27 HEAD_SHA1=$(git rev-parse ${GITHUB_HEAD_REF})
28 FILES=$(git diff --diff-filter=AMR --name-only ${BASE_SHA1}..${HEAD_SHA1} | tr '\n' ' ' )
29 elif [ ! -z $GITHUB_SHA ]; then
30 echo "GitHub push COMMIT $GITHUB_SHA"
31 FILES=$(git diff --diff-filter=AMR --name-only ${GITHUB_SHA}~1..${GITHUB_SHA} | tr '\n' ' ' )
32 elif [ ! -z $TRAVIS_PULL_REQUEST_BRANCH ]; then
33 # if on a PR, just analyse the changed files
34 echo "TRAVIS PR BRANCH: $TRAVIS_PULL_REQUEST_BRANCH"
35 FILES=$(git diff --diff-filter=AMR --name-only $(git merge-base HEAD master) | tr '\n' ' ' )
36 elif [ ! -z $TRAVIS_COMMIT_RANGE ]; then
37 echo "TRAVIS COMMIT RANGE: $TRAVIS_COMMIT_RANGE"
38 FILES=$(git diff --diff-filter=AMR --name-only ${TRAVIS_COMMIT_RANGE/.../..} | tr '\n' ' ' )
42 if ! [ -f "$f" ]; then
43 echo "$f was removed." >>/tmp/ctest-important.log
47 echo "Checking $f" >>/tmp/ctest-important.log
54 *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
65 if diff -u "$m" "$f" >>$ASTYLEDIFF; then
68 echo "File $f needs indentation"
72 if [ -s "$ASTYLEDIFF" ]; then
74 echo "Required indentation updates:"
79 Tips to prevent and resolve:
80 * Enable WITH_ASTYLE in your cmake configuration to format C++ code
81 * Install autopep8 (>= 1.2.1) to format python code
82 * Use "scripts/astyle.sh file" to fix the now badly indented files
83 * Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this
84 in the future (ln -s scripts/prepare-commit.sh .git/hooks/pre-commit) or
85 run it manually before each commit.