git-hook-pre-commit.sh 759 B

123456789101112131415161718192021222324252627
  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. if [ "${ERLFMT_WRITE:-false}" = 'true' ]; then
  13. # shellcheck disable=SC2086
  14. ./scripts/erlfmt -w $files
  15. else
  16. # mix format check is quite fast
  17. which mix && mix format --check-formatted
  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