Last active
May 30, 2019 06:35
-
-
Save jmatsu/3ac8a09f6cd1a4aac747f115584a529d to your computer and use it in GitHub Desktop.
Run `curl -sSL "https://gist.githubusercontent.com/jmatsu/3ac8a09f6cd1a4aac747f115584a529d/raw/dec6d729f481274d7fcc04ed697e87f7f74cf7ac/install.bash" | bash` to prevent master push
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
die() { | |
echo "$*" >&2 | |
exit 1 | |
} | |
warn() { | |
echo "$*" >&2 | |
} | |
if [[ ! -d ".git/hooks" ]]; then | |
warn "could not find .git/hooks directory from the current directory." | |
cd $(git rev-parse --show-toplevel) | |
if (($? != 0)); then | |
die "this may not be a git repository." | |
fi | |
warn "moved to $(pwd)" | |
fi | |
cd .git/hooks | |
if [[ -f "pre-push" ]]; then | |
warn "pre-push already exists." | |
readonly tmp_suffix=$(basename $(mktemp)) | |
mv pre-push "pre-push.${tmp_suffix}" | |
warn "pre-push.${tmp_suffix} has been created as the backup of the current pre-push." | |
fi | |
curl -sSL "https://gist.githubusercontent.com/jmatsu/3ac8a09f6cd1a4aac747f115584a529d/raw/82c2c24b5b776d1b70baf729752b7d4eb909eb38/prevent-pushing-to-master.bash" -o prevent-pushing-to-master.bash | |
chmod +x ./prevent-pushing-to-master.bash | |
ln -s ./prevent-pushing-to-master.bash pre-push | |
echo "$(pwd)/pre-push has been prepared." |
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
#!/usr/bin/env bash | |
set -eu | |
if [[ "${PUSH_TO_MASTER:-false}" == "true" ]]; then | |
exit 0 | |
fi | |
die() { | |
echo "$*" >&2 | |
exit 1 | |
} | |
while read x y remote_ref z; do | |
if [[ "${remote_ref##refs/heads/}" == "master" ]]; then | |
die "Never push to master branch. Please set PUSH_TO_MASTER=true if you want to do it." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment