Last active
March 5, 2022 15:52
-
-
Save willsantos/3c7da8c383fb8b1a9fd6e5817924b334 to your computer and use it in GitHub Desktop.
Hook to block Main branch
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 | |
red='\x1b[41m' | |
nocolor='\x1b[0m' | |
protected_branch='main' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_branch = $current_branch ] | |
then | |
echo -e "${red}You are in the $current_branch,Blocked Branch${nocolor}" | |
read -p "Do you really want to do this? [y/n]" -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
exit 0 # Do run | |
fi | |
exit 1 # dont run | |
else | |
exit 0 # Do run | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Não esquecer de dar permissão de escrita
chmod +x .git/hooks/prepare-commit