Skip to content

Instantly share code, notes, and snippets.

@Hounddog
Created October 15, 2012 10:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hounddog/3891872 to your computer and use it in GitHub Desktop.
Save Hounddog/3891872 to your computer and use it in GitHub Desktop.
PHP Pre commit check for only changed files
#!/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