Last active
January 24, 2020 22:52
-
-
Save kitsune7/c30831cde048d8ce10bca856e399e957 to your computer and use it in GitHub Desktop.
A pre-commit hook to stop you from doing silly things
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 | |
# Requires the `dialog` package to be installed on linux machines | |
# Only supported on Mac OSX and Linux | |
warningString="You're on master. Are you sure you want to commit your changes here?" | |
yesResponse="Alright. Here we go, I guess." | |
noResponse="Cool. Let's keep it safe. Switch to a different branch before you rush to commit next time, okay?" | |
macDialogScript="button returned of (display dialog \"$warningString\" with icon caution buttons {'No', 'Yes'})" | |
branch=`git rev-parse --abbrev-ref HEAD` | |
if [ $branch = 'master' ]; then | |
if [[ "$OSTYPE" == "linux-gnu" ]]; then | |
if [ dialog --title "Warning" --yesno "$warningString" 8 30 ] | |
then | |
echo $yesResponse | |
else | |
echo $noResponse | |
exit 1 | |
fi | |
# Mac OSX | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
if [ `osascript -e "$macDialogScript"` = "Yes" ]; then | |
echo $yesResponse | |
else | |
echo $noResponse | |
exit 1 | |
fi | |
fi | |
fi | |
# Run tests | |
npm test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment