git-hook-pre-commit.sh 471 B

1234567891011121314151617
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. OPT="${1:--c}"
  4. files_dirty="$(git diff --name-only | grep -E '.*\.erl' || true)"
  5. files_cached="$(git diff --cached --name-only | grep -E '.*\.erl' || true)"
  6. if [[ "${files_dirty}" == '' ]] && [[ "${files_cached}" == '' ]]; then
  7. exit 0
  8. fi
  9. files="$(echo -e "${files_dirty} \n ${files_cached}" | xargs)"
  10. # shellcheck disable=SC2086
  11. if ! (./scripts/erlfmt $OPT $files); then
  12. echo "EXECUTE 'make fmt' to fix" >&2
  13. exit 1
  14. fi