pre-commit 718 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 diff --cached --name-only)"
  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 ]]; then
  9. # use php-cs-fixer and get flag of correction
  10. "${root}/bin/php-cs-fixer" -q fix "${staged}"
  11. # if php-cs-fixer fix works, it returns 0
  12. if [[ $? -eq 0 ]]; then
  13. git add "${staged}" # execute git add directly
  14. fi
  15. fi
  16. done
  17. echo "Running php-doc-checker"
  18. "${root}/bin/php-doc-check" src plugins components
  19. # Only commit if there wasn't an error
  20. exit $?