add git hooks

This commit is contained in:
purhan 2021-02-17 14:11:47 +05:30
parent 360f6f1127
commit 491262ff58
2 changed files with 21 additions and 0 deletions

View file

@ -25,3 +25,7 @@
[credential "https://github.com"]
helper = !gh auth git-credential
; global hooks
[core]
hooksPath = /home/purhan/scripts/hooks/git/

17
src/scripts/hooks/git/pre-push Executable file
View file

@ -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