diff options
author | Sam Clegg <sbc@chromium.org> | 2019-06-06 12:52:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-06 12:52:14 -0700 |
commit | 1578cec27d45cf5104480f533fb092e81f0dbeb5 (patch) | |
tree | 1ff96808dd8d2af37d5a8aecd3d6b4b20285071a /clang-tidy-diff.sh | |
parent | 4e299e978fd56692d2a2f5169008009567a36046 (diff) | |
download | binaryen-1578cec27d45cf5104480f533fb092e81f0dbeb5.tar.gz binaryen-1578cec27d45cf5104480f533fb092e81f0dbeb5.tar.bz2 binaryen-1578cec27d45cf5104480f533fb092e81f0dbeb5.zip |
Improve error detection in clang-tidy/clang-format scripts (#2156)
- Error out of shell script if any command fails.
- Don't try to run on travis builds that are not PRs (i.e. don't have any upstream).
- Prefer origin/master over just master (some folks don't use master locally).
- Don't hide stderr by piping it to dev/null.
Diffstat (limited to 'clang-tidy-diff.sh')
-rwxr-xr-x | clang-tidy-diff.sh | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/clang-tidy-diff.sh b/clang-tidy-diff.sh index ece8776f9..292ec6df6 100755 --- a/clang-tidy-diff.sh +++ b/clang-tidy-diff.sh @@ -1,13 +1,28 @@ #!/bin/bash + +set -o errexit + +# When we are running on travis and *not* part of a pull request we don't +# have any upstream branch to compare against. +if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then + echo "Skipping since not running on travis PR" + exit 0 +fi + +if [ -n "$TRAVIS_BRANCH" ]; then + BRANCH=$TRAVIS_BRANCH +else + BRANCH=origin/master +fi + CLANG_DIR=$(dirname $(dirname $(which clang-tidy))) CLANG_TIDY_DIFF=$CLANG_DIR/share/clang/clang-tidy-diff.py -MERGE_BASE=$(git merge-base master HEAD) -TIDY_MSG=$(git diff -U0 $MERGE_BASE | $CLANG_TIDY_DIFF -quiet -p1 2> /dev/null) +TIDY_MSG=$(git diff -U0 $BRANCH... | $CLANG_TIDY_DIFF -quiet -p1 2> /dev/null) if [ -n "$TIDY_MSG" -a "$TIDY_MSG" != "No relevant changes found." ] then echo "Fix clang-tidy errors before committing!" echo # Run clang-tidy once again to show the error - git diff -U0 $MERGE_BASE | $CLANG_TIDY_DIFF -quiet -p1 2> /dev/null + git diff -U0 $BRANCH... | $CLANG_TIDY_DIFF -quiet -p1 2> /dev/null exit 1 fi |