Last active
March 6, 2018 03:12
-
-
Save wkrsz/a6f203bcfdca691ded96 to your computer and use it in GitHub Desktop.
Git pre-push hook that shows changes and ask for confirmation when pushing to production repo.
This file contains hidden or 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. | |
Deployment by pushing code to remote github repo are very convenient | |
but prone to accidents. I wanted something that would force me to | |
review what's being pushed. | |
My Bash-foo is very limited to suggestions for improvements are very welcome. |
This file contains hidden or 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 | |
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 "You're about to push to production, are you sure? [AFFIRMATIVE|NEGATIVE] " -r < /dev/tty | |
echo | |
if [[ $REPLY = 'AFFIRMATIVE' ]]; 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
Excellent!!! Work perfect.