Last active
May 17, 2019 21:31
-
-
Save PetteriVaarala/121944a1d96e6e632e4a98fc3eebc94f to your computer and use it in GitHub Desktop.
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 | |
# Prevent commit to protected branches | |
PROTECTED_BRANCHES=("protected" "master") | |
CURRENT_BRANCH=$(basename "$(git symbolic-ref HEAD)") | |
for PROTECTED_BRANCH in "${PROTECTED_BRANCHES[@]}";do | |
# Split current branch | |
if [ "${CURRENT_BRANCH##*/}" == "${PROTECTED_BRANCH}" ];then | |
read -p "Commit to master, are you sure? (Y|n) " -n 1 -r < /dev/tty | |
echo | |
if echo "$REPLY" | grep -E '^[Y]$' > /dev/null;then | |
exit 0 # Commit | |
fi | |
echo "Aborting commit due protected branch." | |
exit 1 # No Commit | |
fi | |
done | |
exit 0 # Commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment