dawn-cmake/scripts/travis_lint_format.sh

36 lines
1.2 KiB
Bash
Raw Normal View History

2017-11-27 22:04:35 +00:00
#!/bin/bash
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
echo "Running outside of pull request isn't supported yet"
exit 0
fi
# Choose the commit against which to format
base_commit=$(git rev-parse $TRAVIS_BRANCH)
echo "Formatting against $TRAVIS_BRANCH a.k.a. $base_commit..."
echo
2018-04-06 18:52:25 +00:00
skipped_directories="(examples|generator|src/tests/(unittests|end2end)|third_party)"
2017-11-27 22:04:35 +00:00
# Find the files modified that need formatting
2018-07-19 12:57:38 +00:00
files_to_check=$(git diff --diff-filter=ACMR --name-only $base_commit | grep -E "*.(c|cpp|mm|h)$" | grep -vE "^$skipped_directories/*")
2017-11-27 22:04:35 +00:00
if [ -z "$files_to_check" ]; then
echo "No modified files to format."
exit 0
fi
echo "Checking formatting diff on these files:"
echo "$files_to_check"
echo
files_to_check=$(echo $files_to_check | tr '\n' ' ')
# Run git-clang-format, check if it formatted anything
format_output=$(scripts/git-clang-format --binary $1 --commit $base_commit --diff --style=file $files_to_check)
if [ "$format_output" == "clang-format did not modify any files" ] || [ "$format_output" == "no modified files to format" ] ; then
2017-11-27 22:04:35 +00:00
exit 0
fi
# clang-format made changes, print them and fail Travis
echo "Following formatting changes needed:"
echo
echo "$format_output"
exit 1