clang-format.hook 548 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. PATH="${PATH}:/opt/local/bin"; export PATH
  3. STYLE=$(git config --get hooks.clangformat.style)
  4. if [ -n "${STYLE}" ] ; then
  5. STYLEARG="-style=${STYLE}"
  6. else
  7. STYLEARG=""
  8. fi
  9. format_file() {
  10. file="${1}"
  11. if [ -f $file ]; then
  12. clang-format -i ${STYLEARG} ${1}
  13. git add ${1}
  14. fi
  15. }
  16. case "${1}" in
  17. --about )
  18. echo "Runs clang-format on source files"
  19. ;;
  20. * )
  21. for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cxx|cc|h|hh|hpp|inl|tpp)$' ` ; do
  22. format_file "${file}"
  23. done
  24. ;;
  25. esac