pre-commit 777 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
  3. PROJECT=`php -r "echo dirname(dirname(realpath('$0')));"`
  4. # Determine if a file list is passed
  5. if [ "$#" -eq 1 ]
  6. then
  7. oIFS=$IFS
  8. IFS='
  9. '
  10. SFILES="$1"
  11. IFS=$oIFS
  12. fi
  13. SFILES=${SFILES:-$FILES}
  14. echo "Checking PHP Lint..."
  15. for FILE in $SFILES
  16. do
  17. php -l -d display_errors=0 $PROJECT/$FILE
  18. if [ $? != 0 ]
  19. then
  20. echo "Fix the error before commit."
  21. exit 1
  22. fi
  23. FILES="$FILES $PROJECT/$FILE"
  24. done
  25. if [ "$SFILES" != "" ]
  26. then
  27. echo "Running PHPCS"
  28. ./vendor/bin/phpcs --standard=vendor/cakephp/cakephp-codesniffer/CakePHP $SFILES
  29. if [ $? != 0 ]
  30. then
  31. echo "PHPCS Errors found; commit aborted."
  32. exit 1
  33. fi
  34. fi
  35. exit $?