#!/bin/bash function usage() { echo "Usage: $0 test|reformat" } if [ $# -eq 0 ] then usage exit 0 fi if [ -z "$CLANG_FORMAT" ] then CLANG_FORMAT=clang-format echo "No CLANG_FORMAT set. Using $CLANG_FORMAT" fi if ! type "$CLANG_FORMAT" &> /dev/null then echo "The command \"$CLANG_FORMAT\" was not found" exit 1 fi SOURCE_FILES=$(git ls-files src/) if [ "$1" == "reformat" ] then echo "Reformatting source files" # shellcheck disable=2086 echo $CLANG_FORMAT -style=file -i $SOURCE_FILES # shellcheck disable=2086 $CLANG_FORMAT -style=file -i $SOURCE_FILES exit 0 elif [ "$1" == "test" ] then # shellcheck disable=2086 RESULT=$($CLANG_FORMAT -style=file -output-replacements-xml $SOURCE_FILES | grep -c '