Created
October 3, 2016 19:47
-
-
Save rargulati/afd9fdf2968411fe02fbe16d6c3fada5 to your computer and use it in GitHub Desktop.
Prevent any type of push to master
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/sh | |
# Prevent any type of push to master without an explicit confirmation. | |
# On file creation (save and exit), set `chmod +x pre-push`, or this won't execute. | |
# TODO: create branch when user selects `no`. | |
protected_branch='master' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_branch = $current_branch ] | |
then | |
read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
exit 0 # push will execute | |
fi | |
exit 1 # push will not execute | |
else | |
exit 0 # push will execute | |
fi | |
exit 1 # weird state, safely exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment