2016-10-25 22:39:21 -07:00
|
|
|
#!/bin/bash
|
2016-12-13 00:54:38 -08:00
|
|
|
|
2021-08-31 10:16:33 -07:00
|
|
|
# Compare against the master branch, because most development is done against it.
|
|
|
|
base_commit="$(git merge-base HEAD master)"
|
2021-10-05 16:33:12 -07:00
|
|
|
if [ "$base_commit" = "$(git rev-parse HEAD)" ]; then
|
2021-08-31 10:16:33 -07:00
|
|
|
# Prefix of master branch, so compare against parent commit
|
|
|
|
base_commit="$(git rev-parse HEAD^)"
|
2021-10-05 16:33:12 -07:00
|
|
|
echo "Running clang-format against parent commit $base_commit"
|
2016-10-25 22:39:21 -07:00
|
|
|
else
|
2021-10-05 16:33:12 -07:00
|
|
|
echo "Running clang-format against parent commit $base_commit from master branch"
|
2016-10-25 22:39:21 -07:00
|
|
|
fi
|
2021-08-31 10:16:33 -07:00
|
|
|
|
2019-12-16 11:21:18 -08:00
|
|
|
exclude_regex="(.*thirdparty/|.*redismodule.h|.*.java|.*.jsx?|.*.tsx?)"
|
2022-04-13 18:11:30 +01:00
|
|
|
output="$(ci/lint/git-clang-format --commit "$base_commit" --diff --exclude "$exclude_regex")"
|
2020-01-15 11:17:49 -08:00
|
|
|
if [ "$output" = "no modified files to format" ] || [ "$output" = "clang-format did not modify any files" ] ; then
|
2021-10-05 16:33:12 -07:00
|
|
|
echo "clang-format passed."
|
2016-10-25 22:39:21 -07:00
|
|
|
exit 0
|
|
|
|
else
|
2021-10-05 16:33:12 -07:00
|
|
|
echo "clang-format failed:"
|
|
|
|
echo "$output"
|
2016-10-25 22:39:21 -07:00
|
|
|
exit 1
|
|
|
|
fi
|