#!/usr/bin/env bash # Allow the caller to specify a particular version of clang-format to use: : "${CLANG_FORMAT_CMD:=clang-format}" # Find all *.cpp and *.h files, except those in `testing/googletest/` and files # generated by testcase scripts, and run `clang-format` on them: find ./* -type f \( -name '*.h' -o -name '*.cpp' \) \ -not \( -path './testing/googletest/*' -o -name 'generated-testcase.cpp' \) \ -print0 | \ xargs -0 "${CLANG_FORMAT_CMD}" -i # If we get the `--check` option, return an error if there are any changes to # the git working tree after running `clang-format`: if [[ $1 == '--check' ]]; then if ! git diff --quiet; then cat >&2 <