From 59baaabb890540061cac6e0bd47817bc5429bb41 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Fri, 31 May 2019 11:03:06 +0000 Subject: [PATCH] Travis clang-format, cpplint: Use the merge base We previously looked at the diff to the current head of the target branch, which may have moved in comparison to the merge base of a pull request. Thus we sometimes ended up with spurious clang-format errors, talking about changes introduced in another PR. --- .travis.yml | 4 +++- scripts/travis_lint.sh | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f84e2da9dd..f0e80827366 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,9 @@ jobs: clang-format-7 --version # build a pathspec that excludes the files in .clang-format-ignore while read file ; do echo EXCLUDES+="':(top,exclude)$file' " ; done < .clang-format-ignore - git-clang-format-7 --binary clang-format-7 "${TRAVIS_BRANCH}" -- $EXCLUDES + MERGE_BASE=$(git merge-base ${TRAVIS_COMMIT_RANGE%...*} ${TRAVIS_COMMIT_RANGE#*...}) + echo "Checking for formatting errors introduced since $MERGE_BASE" + git-clang-format-7 --binary clang-format-7 $MERGE_BASE -- $EXCLUDES git diff > formatted.diff if [[ -s formatted.diff ]] ; then echo 'Formatting error! The following diff shows the required changes' diff --git a/scripts/travis_lint.sh b/scripts/travis_lint.sh index 6592a3ebdfa..f7b80ed9327 100755 --- a/scripts/travis_lint.sh +++ b/scripts/travis_lint.sh @@ -12,5 +12,6 @@ else git config remote.origin.fetch +refs/heads/$TRAVIS_BRANCH:refs/remotes/origin/$TRAVIS_BRANCH git fetch --unshallow git checkout $TMP_HEAD - $script_folder/run_diff.sh CPPLINT origin/$TRAVIS_BRANCH # Check for errors compared to merge target + MERGE_BASE=$(git merge-base ${TRAVIS_COMMIT_RANGE%...*} ${TRAVIS_COMMIT_RANGE#*...}) + $script_folder/run_diff.sh CPPLINT $MERGE_BASE fi