Skip to content

Commit 59baaab

Browse files
committed
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.
1 parent 6c39035 commit 59baaab

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
clang-format-7 --version
1919
# build a pathspec that excludes the files in .clang-format-ignore
2020
while read file ; do echo EXCLUDES+="':(top,exclude)$file' " ; done < .clang-format-ignore
21-
git-clang-format-7 --binary clang-format-7 "${TRAVIS_BRANCH}" -- $EXCLUDES
21+
MERGE_BASE=$(git merge-base ${TRAVIS_COMMIT_RANGE%...*} ${TRAVIS_COMMIT_RANGE#*...})
22+
echo "Checking for formatting errors introduced since $MERGE_BASE"
23+
git-clang-format-7 --binary clang-format-7 $MERGE_BASE -- $EXCLUDES
2224
git diff > formatted.diff
2325
if [[ -s formatted.diff ]] ; then
2426
echo 'Formatting error! The following diff shows the required changes'

scripts/travis_lint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ else
1212
git config remote.origin.fetch +refs/heads/$TRAVIS_BRANCH:refs/remotes/origin/$TRAVIS_BRANCH
1313
git fetch --unshallow
1414
git checkout $TMP_HEAD
15-
$script_folder/run_diff.sh CPPLINT origin/$TRAVIS_BRANCH # Check for errors compared to merge target
15+
MERGE_BASE=$(git merge-base ${TRAVIS_COMMIT_RANGE%...*} ${TRAVIS_COMMIT_RANGE#*...})
16+
$script_folder/run_diff.sh CPPLINT $MERGE_BASE
1617
fi

0 commit comments

Comments
 (0)