Created
January 18, 2019 18:21
-
-
Save Atlante45/ccfca35ffb5c0fbc4752fa08ca720dbc to your computer and use it in GitHub Desktop.
git pre-push hook that prevent accidental pushes to upstream (Add it to .git/hooks)
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 | |
remote="$1" | |
url="$2" | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
yellow='\033[1;33m' | |
red='\033[0;31m' | |
default='\033[0m' | |
message="I KNOW WHAT I'M DOING" | |
# Allows us to read user input below, assigns stdin to keyboard | |
exec < /dev/tty | |
if [ $remote = "upstream" ] || [[ $url = *"highfidelity/hifi.git" ]] | |
then | |
echo "[pre-push hook] ${yellow}You are about to push to upstream!${default}" | |
echo "[pre-push hook] ${yellow}Enter ${red}${bold}\"$message\"${normal}${yellow} if you want to continue:${default}" | |
read -r -p "[pre-push hook] > " input | |
if [ "$input" = "$message" ] | |
then | |
echo "[pre-push hook] Alrighty then" | |
exit 0 | |
else | |
echo "[pre-push hook] You made the right choice!" | |
exit 1 | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment