Last active
January 18, 2016 18:20
-
-
Save DanielArndt/e220270e5ac8ee38083f 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 | |
contains_element () { | |
local e | |
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done | |
return 1 | |
} | |
protected_branches=("master" "develop") | |
# check each branch being pushed | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
remote_branch=$(sed -e 's,refs/heads/\(.*\),\1,' <<< $remote_ref) | |
if contains_element $remote_branch ${protected_branches[@]} ; | |
then | |
echo "PUSH ABORTED: You are attempting to push directly to protected branch $remote_branch. Use --no-verify to force." | |
exit 1 # push will not execute | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put in
.git/hooks/pre-push