Skip to content

Commit

Permalink
Update check_format to use latest version of clang-format available
Browse files Browse the repository at this point in the history
  - Instead of using particular clang-format-3.8
  • Loading branch information
ArtemSkrebkov committed Nov 30, 2019
1 parent 03a0a2c commit e362d54
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions scripts/check_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function check_shogun_style {
echo "-----"
echo "Shogun Style Checker"
echo "-----"
echo "Running clang-format-3.8 against branch ${2:-}, with hash $BASE_COMMIT"
echo "Running clang-format against branch ${2:-}, with hash $BASE_COMMIT"

COMMIT_FILES=$(git diff --name-only $BASE_COMMIT)

# Use clang-format only on existent files
LIST=("")
for file in $COMMIT_FILES
Expand All @@ -40,24 +40,24 @@ function check_shogun_style {
LIST=("${LIST[@]}" "$file")
fi
done

RESULT_OUTPUT="$(git clang-format-3.8 --commit $BASE_COMMIT --diff --binary `which clang-format-3.8` $LIST)"
GIT_CLANG_FORMAT_BINARY=$(find /usr/bin -name "git-clang-format*" -print0 | xargs -r -0 ls -1 -r | head -1 | xargs -i basename {})
RESULT_OUTPUT="$(${GIT_CLANG_FORMAT_BINARY} --commit $BASE_COMMIT --diff --binary `which clang-format` $LIST)"

if [ "$RESULT_OUTPUT" == "no modified files to format" ] \
|| [ "$RESULT_OUTPUT" == "clang-format-3.8 did not modify any files" ] \
|| [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ] \
|| [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then
echo "clang-format-3.8 passed. \o/"
echo "clang-format passed. \o/"
echo "-----"
exit 0
else
echo "-----"
echo "clang-format failed."
echo "To reproduce it locally please run: "
echo -e "\t1) git checkout ${1:-}"
echo -e "\t2) git clang-format-3.8 --commit $BASE_COMMIT --diff --binary $(which clang-format-3.8)"
echo -e "\t2) $GIT_CLANG_FORMAT_BINARY --commit $BASE_COMMIT --diff --binary $(which clang-format)"
echo "To fix the errors automatically please run: "
echo -e "\t1) git checkout ${1:-}"
echo -e "\t2) git clang-format-3.8 --commit $BASE_COMMIT --binary $(which clang-format-3.8)"
echo -e "\t2) $GIT_CLANG_FORMAT_BINARY --commit $BASE_COMMIT --binary $(which clang-format)"
echo "-----"
echo "Style errors found:"
echo "$RESULT_OUTPUT"
Expand Down

0 comments on commit e362d54

Please sign in to comment.