pre-commit 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env sh
  2. root="$(git rev-parse --show-toplevel)"
  3. # get the list of changed files
  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. if "${root}/bin/php-cs-fixer" -q --config="${root}/.php-cs-fixer.php" fix "${staged}"; then
  12. git add "${staged}" # execute git add directly
  13. fi
  14. fi
  15. done
  16. fi
  17. if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then
  18. echo "Running php-doc-checker"
  19. if echo "${staged_files}" | grep -F ".php"; then
  20. "${root}/bin/php-doc-check" src plugins components
  21. fi
  22. fi
  23. if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_PHPSTAN?}") 2>/dev/null); then
  24. echo "Running phpstan"
  25. make phpstan
  26. fi
  27. # Only commit if there wasn't an error
  28. exit $?