Created
December 11, 2015 03:31
-
-
Save erikcox/5d6d78941ef3faddab9f to your computer and use it in GitHub Desktop.
Add git pre-push hook to check for TODO: in comments
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
# create the pre-commit file & make it executable | |
touch .git/hooks/pre-commit | |
chmod +x .git/hooks/pre-commit | |
# The line below is important! | |
#!/bin/bash | |
# Don't push if TODO is in the source for HEAD | |
dont_push_flag="TODO" | |
flag_found=`git grep --color "$dont_push_flag" HEAD` | |
if [ -n "$flag_found" ] | |
then | |
# Display which commit the first occurence of the flag was found and exit failure | |
commit=`git log --pretty=format:'%Cred%h%Creset' -S "$dont_push_flag" | tail -n1` | |
echo "Found $flag_found, first occurence was in $commit, not pushing" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment