Created
April 10, 2019 13:56
-
-
Save dktapps/ec5c5fefed75968412c69a072406a818 to your computer and use it in GitHub Desktop.
pre-commit hook I use for PocketMine-MP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
errors=0 | |
IFS=$'\n' FILENAMES=$(git diff --cached --name-only | grep ".php") | |
for (( i=0; i<${#FILENAMES[@]}; i++ )) | |
do | |
if [ -f "${FILENAMES[$i]}" ]; then | |
OUTPUT=$(git grep -h --cached ^ -- "${FILENAMES[$i]}" | php -l ) | |
if [ $? -ne 0 ]; then | |
echo -n "${FILENAMES[$i]} lint scan failed: " | |
echo $OUTPUT | |
((errors++)) | |
fi | |
fi | |
done | |
if [ $errors -gt 0 ]; then | |
echo "$errors files failed lint scan" | |
exit 1 | |
fi | |
# If there are whitespace errors, print the offending file names and fail. | |
git diff-index --check --cached $against -- || exit 1 | |
#exec git diff --check 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
#exec php phpunit.phar --bootstrap vendor/autoload.php tests/phpunit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment