diff --git a/src/.gitconfig b/src/.gitconfig index d25e77f..c8841cd 100644 --- a/src/.gitconfig +++ b/src/.gitconfig @@ -25,3 +25,7 @@ [credential "https://github.com"] helper = !gh auth git-credential +; global hooks +[core] + hooksPath = /home/purhan/scripts/hooks/git/ + diff --git a/src/scripts/hooks/git/pre-push b/src/scripts/hooks/git/pre-push new file mode 100755 index 0000000..100333e --- /dev/null +++ b/src/scripts/hooks/git/pre-push @@ -0,0 +1,17 @@ +#!/bin/bash + +current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') +protected_branches="main master dev" + +if [[ "$protected_branches" == *"$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