Skip to content

Instantly share code, notes, and snippets.

@PetteriVaarala
Last active May 17, 2019 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetteriVaarala/121944a1d96e6e632e4a98fc3eebc94f to your computer and use it in GitHub Desktop.
Save PetteriVaarala/121944a1d96e6e632e4a98fc3eebc94f to your computer and use it in GitHub Desktop.
#!/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