Skip to content

Instantly share code, notes, and snippets.

@Atlante45
Created January 18, 2019 18:21
Show Gist options
  • Save Atlante45/ccfca35ffb5c0fbc4752fa08ca720dbc to your computer and use it in GitHub Desktop.
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)
#!/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