git-hook-pre-commit.sh 579 B

123456789101112131415161718192021
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. OPT="${1:--c}"
  4. # mix format check is quite fast
  5. which mix && mix format --check-formatted
  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. # shellcheck disable=SC2086
  13. if ! (./scripts/erlfmt $OPT $files); then
  14. echo "EXECUTE 'make fmt' to fix" >&2
  15. exit 1
  16. fi
  17. ./scripts/apps-version-check.sh