git-hook-pre-commit.sh 753 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. if [ -n "${FORCE:-}" ]; then
  4. exit 0
  5. fi
  6. files_dirty="$(git diff --name-only | grep -E '.*\.erl' || true)"
  7. files_cached="$(git diff --cached --name-only | grep -E '.*\.erl' || true)"
  8. if [[ "${files_dirty}" == '' ]] && [[ "${files_cached}" == '' ]]; then
  9. exit 0
  10. fi
  11. files="$(echo -e "${files_dirty} \n ${files_cached}" | xargs)"
  12. # mix format check is quite fast
  13. which mix && mix format --check-formatted
  14. if [ "${ERLFMT_WRITE:-false}" = 'true' ]; then
  15. # shellcheck disable=SC2086
  16. ./scripts/erlfmt -w $files
  17. else
  18. # shellcheck disable=SC2086
  19. if ! (./scripts/erlfmt -c $files); then
  20. echo "EXECUTE 'make fmt-diff' to fix" >&2
  21. exit 1
  22. fi
  23. ./scripts/apps-version-check.sh
  24. fi