pre-commit 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env sh
  2. root="$(git rev-parse --show-toplevel)"
  3. # get the list of changed files that didn't get only partially added
  4. staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")"
  5. if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); then
  6. echo "Running php-cs-fixer on edited files"
  7. for staged in ${staged_files}; do
  8. # work only with existing files
  9. if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then
  10. # use php-cs-fixer and get flag of correction
  11. CS_FIXER_FILE="${staged}" make cs-fixer
  12. git add "${staged}"
  13. fi
  14. done
  15. fi
  16. if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then
  17. if echo "${staged_files}" | grep -F ".php" > /dev/null 2>&1; then
  18. echo "Running php-doc-checker"
  19. make doc-check < /dev/tty
  20. fi
  21. fi
  22. if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_PHPSTAN?}") 2>/dev/null); then
  23. echo "Running phpstan"
  24. make phpstan
  25. fi
  26. # Only commit if there wasn't an error
  27. exit $?