You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

34 lines
788 B

  1. #!/bin/bash
  2. pass=true
  3. files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(php|phtml)$')
  4. if [ "$files" != "" ]; then
  5. # Run php syntax check before commit
  6. while read -r file; do
  7. php -l "$file"
  8. if [ $? -ne 0 ]; then
  9. pass=false
  10. fi
  11. done <<< "$files"
  12. # Run php-cs-fixer validation before commit
  13. echo "$files" | xargs ./vendor/bin/php-cs-fixer fix --diff --config .php_cs.dist
  14. if [ $? -ne 0 ]; then
  15. pass=false
  16. fi
  17. # Automatically add files that may have been fixed by php-cs-fixer
  18. echo "$files" | xargs git add
  19. fi
  20. if $pass; then
  21. exit 0
  22. else
  23. echo ""
  24. echo "PRE-COMMIT HOOK FAILED:"
  25. echo "Code style validation failed. Please fix errors and try committing again."
  26. exit 1
  27. fi