check-format.sh 604 B

123456789101112131415161718192021
  1. #!/usr/bin/env bash
  2. SOURCES=$(find $(git rev-parse --show-toplevel) | grep -E "\.(cpp|cc|c|h)\$")
  3. CLANG_FORMAT=$(which clang-format)
  4. if [ $? -ne 0 ]; then
  5. CLANG_FORMAT=$(which clang-format)
  6. if [ $? -ne 0 ]; then
  7. echo "[!] clang-format not installed. Unable to check source file format policy." >&2
  8. exit 1
  9. fi
  10. fi
  11. set -x
  12. for file in ${SOURCES};
  13. do
  14. $CLANG_FORMAT ${file} > expected-format
  15. diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
  16. done
  17. exit $($CLANG_FORMAT --output-replacements-xml ${SOURCES} | grep -E -c "</replacement>")