Created
February 1, 2012 14:23
-
-
Save kotnik/1717274 to your computer and use it in GitHub Desktop.
Drupal pre-commit hook
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 | |
# Author: Remigijus Jarmalavičius <[email protected]> | |
# Author: Vytautas Povilaitis <[email protected]> | |
# Modifications: Nikola Kotur <[email protected]> | |
ROOT_DIR="$(pwd)/" | |
LIST=$(git status | grep -e '\#.*\(modified\|added\)') | |
ERRORS_BUFFER="" | |
for file in $LIST | |
do | |
if [ "$file" == '#' ]; then | |
continue | |
fi | |
if [ $(echo "$file" | grep 'modified') ]; then | |
FILE_ACTION="modified" | |
elif [ $(echo "$file" | grep 'added') ]; then | |
FILE_ACTION="added" | |
else | |
EXTENSION=$(echo "$file" | grep -e "php$\|module$\|inc$\|install$") | |
if [ "$EXTENSION" != "" ]; then | |
echo "Checking $FILE_ACTION file: $file" | |
# Checking for PHP errors | |
ERRORS=$(php -l $ROOT_DIR$file 2>&1 | grep "Parse error") | |
DEBUGGING="" | |
if [ "$ERRORS" != "" ]; then | |
if [ "$ERRORS_BUFFER" != "" ]; then | |
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS" | |
else | |
ERRORS_BUFFER="$ERRORS" | |
fi | |
echo "Syntax errors found in file: $file " | |
fi | |
# Checking for leftover debug code | |
ERRORS=$(grep -e "dpm([^\r\n]*)\|dsm([^\r\n]*)\|krumo([^\r\n]*)" $ROOT_DIR$file 2>&1) | |
if [ "$ERRORS" != "" ]; then | |
if [ "$ERRORS_BUFFER" != "" ]; then | |
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS" | |
else | |
ERRORS_BUFFER="$ERRORS" | |
fi | |
DEBUGGING="yes" | |
echo "Debugging code found in file: $file " | |
fi | |
fi | |
fi | |
done | |
if [ "$ERRORS_BUFFER" != "" ]; then | |
echo | |
if [ "$DEBUGGING" != "" ]; then | |
echo "This debugging code was found in try-to-commit files: " | |
else | |
echo "These errors were found in try-to-commit files: " | |
fi | |
echo -e $ERRORS_BUFFER | |
echo | |
echo "Can't commit, fix errors first." | |
exit 1 | |
else | |
echo "Commited successfully." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment