Skip to content
This repository has been archived by the owner on Mar 6, 2021. It is now read-only.

Commit

Permalink
run phpcs on staged version of file(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo authored and s0enke committed Jul 29, 2010
1 parent f73a7fc commit 38e58ab
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions phpcs-pre-commit/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
# PHP CodeSniffer pre-commit hook for git
#
# @author Soenke Ruempler <soenke@ruempler.eu>
# @author Sebastian Kaspari <s.kaspari@googlemail.com>
#
# see the README

PHPCS_BIN=/usr/bin/phpcs
PHPCS_CODING_STANDARD=PEAR
PHPCS_IGNORE=
OUTPUT=""
PROHIBIT_COMMIT=0

# parse config
CONFIG_FILE=$(dirname $0)/config
Expand Down Expand Up @@ -62,12 +65,24 @@ else
IGNORE=""
fi

OUTPUT=$($PHPCS_BIN -s --standard=$PHPCS_CODING_STANDARD $IGNORE $FILES_TO_CHECK)
RETVAL=$?
# Run phpcs on staged content of every staged file
for FILE in $FILES_TO_CHECK
do
ID=`git diff-index --cached HEAD $FILE | cut -d " " -f4`
git cat-file blob $ID > phpcs.tmp
PHPCS_OUTPUT=`$PHPCS_BIN -s --standard=$PHPCS_CODING_STANDARD $IGNORE phpcs.tmp`
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
OUTPUT="SRC: $FILE$PHPCS_OUTPUT\n\n$OUTPUT"
PROHIBIT_COMMIT="$RETVAL"
fi
rm phpcs.tmp
done

if [ $RETVAL -ne 0 ]; then
echo "$OUTPUT" | less
if [ $PROHIBIT_COMMIT -ne 0 ]; then
echo -e "$OUTPUT" | less
fi

exit $RETVAL
exit $PROHIBIT_COMMIT


0 comments on commit 38e58ab

Please sign in to comment.