Last active
August 29, 2015 14:16
-
-
Save ajvargo/dee0dc97e864d3169111 to your computer and use it in GitHub Desktop.
My version of protecting against a force push
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
#!/usr/bin/env bash | |
# Prevents force-pushing to certain branches w.o confirmation | |
# install to <repo>/.git/hooks/ | |
# chmod +x | |
protected_branches="^(master|production)" | |
current_branch=`git rev-parse --abbrev-ref HEAD` | |
push_command=`ps -ocommand= -p $PPID` | |
force_push="force|delete|-f" | |
# to make it purty | |
red=$'\033[0;31m' | |
nc=$'\033[0m' | |
bul=$'\33[1;4m' | |
nobul=$'\33[24;2m' | |
if [[ "$current_branch" =~ $protected_branches && "$push_command" =~ $force_push ]] | |
then | |
read -p "You're about to ${red}${bul}force push${nobul} ${red}$current_branch${nc}, 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment