Skip to content

Instantly share code, notes, and snippets.

@adirkuhn
Forked from filipekiss/php-lint-pre-commit.sh
Created April 18, 2018 11:22
Show Gist options
  • Save adirkuhn/9a2228da412a27225d00ae6ca20ebe96 to your computer and use it in GitHub Desktop.
Save adirkuhn/9a2228da412a27225d00ae6ca20ebe96 to your computer and use it in GitHub Desktop.
A *really* simple git pre-commit-hook that lints all staged PHP files.
#!/bin/bash
stagedFiles=$(git diff-index --cached HEAD | grep ".php" | grep "^:" | cut -f2);
phpLintErrors=0
echo "PHP will now lint all the php staged files..."
echo ""
for file in $stagedFiles
do
echo "PHP is linting $file...";
echo ""
php -l $file
RETVAL=$?
if [[ $RETVAL != 0 ]]
then
phpLintErrors=1
fi
echo ""
done
if [[ $phpLintErrors == 1 ]]
then
echo ""
echo "-----"
echo "Please, correct the errors above. Commit aborted."
echo "-----"
exit 1
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment