Skip to content

Instantly share code, notes, and snippets.

@dmelo
Last active November 9, 2017 11:26
Show Gist options
  • Save dmelo/cf9f09c5780bc63e2f2c2bcfaba75161 to your computer and use it in GitHub Desktop.
Save dmelo/cf9f09c5780bc63e2f2c2bcfaba75161 to your computer and use it in GitHub Desktop.
Git update hook script that only accepts the push if all php files updated or added are complient with PSR2
#!/bin/sh
#
# Update hook script that only accepts the push if all php files updated or
# added are complient with PSR2
# --- Command line
refname="$1"
oldrev="$2"
newrev="$3"
phpcs="/usr/local/bin/phpcs"
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
exit 1
fi
RET=0
for filename in $(git diff-tree --diff-filter=ACMRTUXB --name-only -r $oldrev..$newrev | grep "\.php$")
do
echo "Processing file $filename"
git show $newrev:$filename | $phpcs --standard=PSR2
if [ 0 != $? ]
then
RET=1
fi
done
exit $RET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment