pre-commit 742 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  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. echo "Running php-cs-fixer on edited files"
  6. for staged in ${staged_files}; do
  7. # work only with existing files
  8. if [ -f "${staged}" ] && [[ "${staged}" = *.php ]]
  9. then
  10. # use php-cs-fixer and get flag of correction
  11. if "${root}/bin/php-cs-fixer" -q fix "${staged}"
  12. then
  13. git add "${staged}" # execute git add directly
  14. fi
  15. fi
  16. done
  17. echo "Running php-doc-checker"
  18. if echo "${staged_files}" | grep -F ".php"; then
  19. "${root}/bin/php-doc-check" src plugins components
  20. fi
  21. # Only commit if there wasn't an error
  22. exit $?