Created
November 4, 2019 11:34
-
-
Save ePirat/5e0b2be2d02bc7e8567c1efcdbee70b7 to your computer and use it in GitHub Desktop.
Push check git hook
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 | |
protected_remote='origin' | |
protected_branch='master' | |
current_remote="$1" | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_remote = $current_remote ] | |
then | |
read -p "You're about to push to $current_remote, 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 | |
if [ $protected_branch = $current_branch ] | |
then | |
read -p "You're about to push $current_branch, 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
Put this at
.git/hooks/pre-push