Last active
May 17, 2016 12:06
-
-
Save ktec/62099005a6f94c6e2924c328bb7103cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Whenever you push to remote that has "production" in its name, | |
this hook will show commits and changes and then ask for confirmation. | |
Copy or symlink to: | |
.git/hooks/pre-push. | |
Make the file executable: | |
chmod +x .git/hooks/pre-push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$1" =~ "production" ]]; then | |
read -a array | |
pushed_ref=${array[1]} | |
remote_ref=${array[3]} | |
echo "You are pushing to PRODUCTION! Here are the changes you're about to push:" | |
echo | |
echo "# Commits:" | |
git log --oneline -5 $remote_ref...$pushed_ref | |
echo | |
echo "# Files changed:" | |
git diff --name-only $remote_ref $pushed_ref | |
echo | |
echo | |
read -p "Are you sure? [Y] " -r < /dev/tty | |
echo | |
if [[ $REPLY = 'Y' ]]; then | |
exit 0 | |
else | |
exit 1 | |
fi | |
else | |
exit 0 # push will execute | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment