Skip to content

Instantly share code, notes, and snippets.

@cbandy
Last active September 28, 2015 01:07
Show Gist options
  • Select an option

  • Save cbandy/1360674 to your computer and use it in GitHub Desktop.

Select an option

Save cbandy/1360674 to your computer and use it in GitHub Desktop.
git pre-commit hook
#!/bin/sh
# Run tools on files in the index
git diff --cached --name-status \
| awk '$1 != "D" && $1 != "R" { $1 = ""; print }' \
| git checkout-index --stdin --temp \
| while read tmp orig
do
case $orig in
*.php)
lint=`php -l $tmp` || echo "$lint" | sed -e "s#$tmp#$orig#"
phpcs --standard=Kohana --tab-width=4 $tmp \
| sed -e '1 { /^[[:blank:]]*$/ d; }' -e "/^FILE:/ s#$tmp#$orig#"
;;
*)
esac
rm $tmp
done \
| awk '{ print } END { exit FNR }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment