diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-01-04 11:03:31 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-01-04 11:03:33 +0100 |
commit | 85db1d5f02fabf03d2cfb5f4bbf662316f69e55d (patch) | |
tree | 006914e98ee1837cfe32f5be63325de068b6ea82 | |
parent | 8832a17f12995c48b9c61194085202fa0abf84bb (diff) |
Add script to warn about pushing to master
-rw-r--r-- | scripts/hooks/pre-push.protect-master.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/hooks/pre-push.protect-master.sh b/scripts/hooks/pre-push.protect-master.sh new file mode 100644 index 00000000..c659a0d9 --- /dev/null +++ b/scripts/hooks/pre-push.protect-master.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# +# The following snippet can be used to WARN about pushing to master +# +# Aborting the push is possible +# + +protected_branch='master' +current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') + +if [ $protected_branch = $current_branch ]; then + read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty + echo + if echo $REPLY | grep -E '^[Yy]$' > /dev/null; then + exit 0 # push will execute + fi + exit 1 # push will not execute +else + exit 0 # push will execute +fi + |