Last active
August 29, 2015 14:21
-
-
Save jennielees/d7816649ef22db53438c to your computer and use it in GitHub Desktop.
~/bin/git-sanity
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 | |
red='\033[0;31m' | |
yellow='\033[0;33m' | |
reset='\033[0m' | |
stopship_found=0 | |
print_found=0 | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
for file in $( git diff --name-only --staged $branch ) | |
do | |
if [ ! -f $file ] | |
then | |
continue | |
fi | |
if [[ $file == bin* ]] || [[ $file == migrations* ]] | |
then | |
continue | |
fi | |
# Look for STOPSHIP statements | |
stopship=$(grep -Hn 'STOPSHIP' $file) | |
if [ -n "$stopship" ] | |
then | |
echo -e ${red}"Stopship statements found:"${reset} | |
stopship_found=$((stopship_found + 1)) | |
echo "$stopship" | |
fi | |
# Look for print statements (but try not to find words with 'print' in them | |
print=$(grep -Hn '[\^\t ]print[ (]' $file) | |
if [ -n "$print" ] | |
then | |
echo -e ${yellow}"Debug statements found:"${reset} | |
print_found=$((print_found + 1)) | |
echo "$print" | |
fi | |
done | |
# Exit with error if we found stopship | |
if [ $stopship_found -gt 0 ] | |
then | |
exit 2 | |
fi | |
# Exit with warning if we found print statements | |
if [ $print_found -gt 0 ] | |
then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment