Created
July 15, 2014 08:31
-
-
Save jbudziak/e259b684ba173af57963 to your computer and use it in GitHub Desktop.
hook/pre-commit
This file contains hidden or 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 | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
against=f737485baee8b0edc5ef4d00c498305578d630fd | |
fi | |
# Redirect output to stderr. | |
exec 1>&2 | |
keywords=(dpm dvm print_r var_dump throw console.log debugger) | |
keywords_for_grep=$(printf "|%s" "${keywords[@]}") | |
keywords_for_grep=${keywords_for_grep:1} | |
files_changed=`git diff-index --name-only HEAD --` | |
`git grep -q -E "$keywords_for_grep" $files_changed` | |
number_of_results=$? | |
if [ $number_of_results -eq 0 ] | |
then | |
echo "# Check following lines:" | |
for FILE in ${files_changed[*]} ; do | |
for keyword in ${keywords[*]} ; do | |
`git grep -q $keyword $FILE` | |
result_for_file=$? | |
if [ $result_for_file -eq 0 ] | |
then | |
LINE=`git grep -n $keyword $FILE | awk -F ":" '{print $2}'` | |
echo "$FILE contains $keyword at line $LINE." | |
fi | |
done | |
done | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment