Created
November 10, 2018 23:18
-
-
Save zilahir/29e51a76f4dc1739c7635cfde837099c to your computer and use it in GitHub Desktop.
pre-push lock master branch
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 | |
protected_branch='master' | |
policy="\n\n[Policy] Never push code directly to the "$protected_branch" branch! ("$protected_branch" is locked! )\n\n" | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
push_command=$(ps -ocommand= -p $PPID) | |
is_destructive='force|delete|\-f' | |
will_remove_protected_branch=':'$protected_branch | |
do_exit(){ | |
echo -e $policy | |
exit 1 | |
} | |
if [[ $push_command =~ $is_destructive ]] && [ $current_branch = $protected_branch ]; then | |
do_exit | |
fi | |
if [[ $push_command =~ $is_destructive ]] && [[ $push_command =~ $protected_branch ]]; then | |
do_exit | |
fi | |
if [[ $push_command =~ $will_remove_protected_branch ]]; then | |
do_exit | |
fi | |
# Prevent ALL pushes to protected_branch | |
if [[ $push_command =~ $protected_branch ]] || [ $current_branch = $protected_branch ]; then | |
do_exit | |
fi | |
unset do_exit | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment