Skip to content

Instantly share code, notes, and snippets.

@jennielees
Created February 26, 2015 18:29
Show Gist options
  • Save jennielees/05056aa383016f8d5d08 to your computer and use it in GitHub Desktop.
Save jennielees/05056aa383016f8d5d08 to your computer and use it in GitHub Desktop.
Bash Sanity checker
#!/bin/bash
# If added to $PATH, this file will be available as `git sanity`.
red='\033[0;31m'
yellow='\033[0;33m'
reset='\033[0m'
stopship_found=0
print_found=1
# Looks for files in the current working patch (diff against master)
# and checks for STOPSHIP or print statements.
for file in $( git diff --name-only master )
do
# 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