dotnet_format.sh 934 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. # This script runs dotnet format on all relevant files in the repo.
  3. # This is the primary script responsible for fixing style violations in C# files.
  4. set -uo pipefail
  5. # Loops through all C# projects tracked by Git.
  6. git ls-files -- '*.csproj' \
  7. ':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' |
  8. while read -r f; do
  9. # Run dotnet format.
  10. dotnet format "$f"
  11. done
  12. diff=$(git diff --color)
  13. # If no diff has been generated all is OK, clean up, and exit.
  14. if [ -z "$diff" ] ; then
  15. printf "Files in this commit comply with the dotnet format style rules.\n"
  16. exit 0
  17. fi
  18. # A diff has been created, notify the user, clean up, and exit.
  19. printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
  20. echo "$diff"
  21. printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
  22. exit 1