pre-commit 757 B

123456789101112131415161718
  1. # Useful precomit hooks
  2. # Please see https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks for instructions on installation.
  3. # Crystal linter
  4. # This is a modified version of the pre-commit hook from the crystal repo. https://github.com/crystal-lang/crystal/blob/master/scripts/git/pre-commit
  5. # Please refer to that if you'd like an version that doesn't automatically format staged files.
  6. changed_cr_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.cr$')
  7. if [ ! -z "$changed_cr_files" ]; then
  8. if [ -x bin/crystal ]; then
  9. # use bin/crystal wrapper when available to run local compiler build
  10. bin/crystal tool format $changed_cr_files >&2
  11. else
  12. crystal tool format $changed_cr_files >&2
  13. fi
  14. git add $changed_cr_files
  15. fi