Created
April 7, 2014 17:52
-
-
Save maruf89/10025286 to your computer and use it in GitHub Desktop.
Git pre-push hook that will throw an error if you try pushing any code with `DONT PUSH ME` in it
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 | |
# File lives in .git/hooks/pre-push | |
# If the following text is found anywhere in the source for HEAD, we will prevent pushing | |
dont_push_flag="DONT PUSH ME" | |
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 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment