2016-10-25 22:39:21 -07:00
|
|
|
#!/bin/bash
|
2016-12-13 00:54:38 -08:00
|
|
|
|
2020-01-15 11:17:49 -08:00
|
|
|
if [ -z "${TRAVIS_PULL_REQUEST-}" ] || [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
|
2016-10-25 22:39:21 -07:00
|
|
|
# Not in a pull request, so compare against parent commit
|
|
|
|
base_commit="HEAD^"
|
2020-01-15 11:17:49 -08:00
|
|
|
echo "Running clang-format against parent commit $(git rev-parse "$base_commit")"
|
2016-10-25 22:39:21 -07:00
|
|
|
else
|
2020-05-19 08:29:17 -07:00
|
|
|
base_commit="$(git merge-base "${TRAVIS_BRANCH}" HEAD)"
|
2020-01-15 11:17:49 -08:00
|
|
|
echo "Running clang-format against branch $base_commit, with hash $(git rev-parse "$base_commit")"
|
2016-10-25 22:39:21 -07:00
|
|
|
fi
|
2019-12-16 11:21:18 -08:00
|
|
|
exclude_regex="(.*thirdparty/|.*redismodule.h|.*.java|.*.jsx?|.*.tsx?)"
|
2020-01-15 11:17:49 -08:00
|
|
|
output="$(ci/travis/git-clang-format --binary clang-format --commit "$base_commit" --diff --exclude "$exclude_regex")"
|
|
|
|
if [ "$output" = "no modified files to format" ] || [ "$output" = "clang-format did not modify any files" ] ; then
|
2016-10-25 22:39:21 -07:00
|
|
|
echo "clang-format passed."
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "clang-format failed:"
|
|
|
|
echo "$output"
|
|
|
|
exit 1
|
|
|
|
fi
|