git-hook-pre-commit.sh 623 B

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