Modify the variable to change the protected git branch. Drop pre-commit
into .git/hooks to use.
Last active
September 29, 2017 10:46
-
-
Save gotpop/ef00f4b4cdfaf75abdfcd3c2819ffe16 to your computer and use it in GitHub Desktop.
Modify the variable to change the protected git 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 | |
protected_branch='develop' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_branch = $current_branch ] | |
then | |
read -p "You're about to commit to develop, is that really a world that you want to live in? [y|n] " -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
echo "You just committed to develop!" | |
exit 0 # push will execute | |
fi | |
echo "You didn't commit to develop - phew!" | |
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