clang_format.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. # This script runs clang-format and fixes copyright headers on all relevant files in the repo.
  3. # This is the primary script responsible for fixing style violations.
  4. set -uo pipefail
  5. # Loops through all code files tracked by Git.
  6. git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \
  7. ':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' |
  8. while read -r f; do
  9. # Run clang-format.
  10. clang-format --Wno-error=unknown -i "$f"
  11. # Fix copyright headers, but not all files get them.
  12. if [[ "$f" == *"inc" ]]; then
  13. continue
  14. elif [[ "$f" == *"glsl" ]]; then
  15. continue
  16. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then
  17. continue
  18. fi
  19. python misc/scripts/copyright_headers.py "$f"
  20. done
  21. diff=$(git diff --color)
  22. # If no patch has been generated all is OK, clean up, and exit.
  23. if [ -z "$diff" ] ; then
  24. printf "Files in this commit comply with the clang-tidy style rules.\n"
  25. exit 0
  26. fi
  27. # A patch has been created, notify the user, clean up, and exit.
  28. printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
  29. echo "$diff"
  30. printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
  31. exit 1