Created
May 9, 2015 09:06
-
-
Save ottok/ee1384d8229e83b6486e to your computer and use it in GitHub Desktop.
Example of a .git/hooks/pre-commit for PHP developers
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
#!/bin/bash | |
for FILE in $(git diff --cached --name-only); do | |
if [[ "$FILE" =~ \.php$ ]]; then | |
php -l "$FILE" 1> /dev/null | |
if [[ $? -ne 0 ]]; then | |
echo -e "\e[1;33mAborting commit: PHP code contains syntax errors\e[0m" >&2 | |
exit 1 | |
fi | |
fi | |
done | |
for FILE in $(git diff --cached --name-only); do | |
if [[ "$FILE" =~ \.php$ ]]; then | |
phpcs -n "$FILE" | |
if [ $? -ne 0 ]; then | |
echo -e "\e[1;33mAborting commit: PHP code violates coding standards\e[0m" >&2 | |
exit 1 | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment