pre-commit 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # Enforce citra's whitespace policy
  3. git config --local core.whitespace tab-in-indent,trailing-space
  4. paths_to_check="src/ CMakeLists.txt"
  5. # If there are whitespace errors, print the offending file names and fail.
  6. if ! git diff --cached --check -- $paths_to_check ; then
  7. cat<<END;
  8. Error: This commit would contain trailing spaces or tabs, which is against this repo's policy.
  9. Please correct those issues before commiting. (Use 'git diff --check' for more details)
  10. If you know what you are doing, you can try 'git commit --no-verify' to bypass the check
  11. END
  12. exit 1
  13. fi
  14. # Check for tabs, since tab-in-indent catches only those at the beginning of a line
  15. if git diff --cached -- $paths_to_check | egrep '^\+.* '; then
  16. cat<<END;
  17. Error: This commit would contain a tab, which is against this repo's policy.
  18. If you know what you are doing, you can try 'git commit --no-verify' to bypass the check.
  19. END
  20. exit 1
  21. fi
  22. for f in $(git diff --name-only --diff-filter=ACMRTUXB --cached); do
  23. if ! echo "$f" | egrep -q "[.](cpp|h)$"; then
  24. continue
  25. fi
  26. if ! echo "$f" | egrep -q "^src/"; then
  27. continue
  28. fi
  29. d=$(diff -u "$f" <(clang-format "$f"))
  30. if ! [ -z "$d" ]; then
  31. echo "!!! $f not compliant to coding style, here is the fix:"
  32. echo "$d"
  33. fail=1
  34. fi
  35. done
  36. exit "$fail"