Skip to content

Instantly share code, notes, and snippets.

@shabith
Last active April 6, 2017 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shabith/653a29ed1e9835e71fb0a4662523cf85 to your computer and use it in GitHub Desktop.
Save shabith/653a29ed1e9835e71fb0a4662523cf85 to your computer and use it in GitHub Desktop.
git hook with confirmation message
#!/bin/sh
# https://gist.github.com/shabith/653a29ed1e9835e71fb0a4662523cf85
# git hook with confimation message
# this pre-push git hook will show a confirmation message and according to the answer (y or n) by user it will proceed or exit.
# Please note that this has been tested only in OSX terminal
# Allow us to read user input below, assigns stdin to keyboard
exec < /dev/tty
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ "master" = $branch ]; then
while true; do
echo "\n";
read -p "๐Ÿšจ ๐Ÿ‘ฎ Did you merge with the upstream/master branch? (Y/n) " yn
if [ "$yn" = "" ]; then
yn='N'
fi
case $yn in
[Nn] ) echo "\n๐Ÿ™…โ€ Please merge with upstream/master branch before pushing to orgin/master. Thanks!\n"; exit 1;;
[Yy] ) echo "\n๐Ÿ‘๐Ÿฝ All good then. Thanks!\n"; break; exit 0;;
* ) echo "\n๐Ÿ’€ Please answer y or n for Yes ๐Ÿ‘๐Ÿฝ or No ๐Ÿ‘Ž๐Ÿฝ \n"; exit 1;;
esac
done
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment