summaryrefslogtreecommitdiffstats
path: root/scripts/hooks/pre-push.protect-master.sh
blob: c659a0d95c7a9c6d399b7e00fbcd6f3ca9ef874f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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