1#!/usr/bin/env bash 2 3# Arg used to specify non-'origin/master' comparison branch 4ORIGIN_BRANCH=${1:-"origin/master"} 5CLANG_BINARY=${2:-"`which clang-format-9`"} 6 7# Run git-clang-format to check for violations 8CLANG_FORMAT_OUTPUT=$(git-clang-format --diff $ORIGIN_BRANCH --extensions c,cpp,h,hpp --binary $CLANG_BINARY) 9 10# Check for no-ops 11grep '^no modified files to format$' <<<"$CLANG_FORMAT_OUTPUT" && exit 0 12grep '^clang-format did not modify any files$' <<<"$CLANG_FORMAT_OUTPUT" && exit 0 13 14# Dump formatting diff and signal failure 15echo -e "\n==== FORMATTING VIOLATIONS DETECTED ====\n" 16echo "$CLANG_FORMAT_OUTPUT" 17exit 1 18