Last active
August 30, 2018 17:57
-
-
Save a-kinder/20475721f891fcf12f98ff962cff25e5 to your computer and use it in GitHub Desktop.
Blocks commits to master unless `-n` flag is provided
This file contains hidden or 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 | |
# Stops accidental commits to master. Adapted from https://gist.github.com/ColCh/9d48693276aac50cac37a9fce23f9bda | |
# Install in project: | |
# install or symlink at .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
#!/bin/bash | |
protected_branch='master' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_branch = $current_branch ] | |
then | |
echo -en "\033[31mCommit to master? [y|n] \033[0m" | |
echo -en "\033[1m" | |
read -n 1 -r < /dev/tty | |
echo -en "\033[0m" | |
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