Created
October 15, 2012 10:29
-
-
Save Hounddog/3891872 to your computer and use it in GitHub Desktop.
PHP Pre commit check for only changed files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Go to root of the repository | |
echo 'Checking PHPCS'; | |
width=$(tput cols); | |
if [ `git rev-parse --verify HEAD` ]; then | |
against='HEAD' | |
else | |
against='4b825dc642cb6eb9a060e54bf8d69288fbee4904' | |
fi | |
commitFiles=`git diff-index --cached --name-only $against` | |
args="-s --report-width=$width --standard=PSR" | |
phpFiles=""; | |
phpFilesCount=0; | |
for f in $commitFiles; do | |
if [[ ! -e $f ]]; then | |
continue; | |
fi | |
if [[ $f =~ \.(php|ctp)$ ]]; then | |
phpFilesCount=$phpFilesCount+1 | |
phpFiles="$phpFiles $f" | |
fi | |
done; | |
if [[ $phpFilesCount = 0 ]]; then | |
exit 0; | |
fi | |
if [[ $phpFilesCount > 2 ]]; then | |
args="$args --report=summary" | |
fi | |
vendor/bin/phpcs $args $phpFiles --ignore=*/data/Doctrine/Migration/*,*/application/proxies/*,*/script/hooks/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment