Created
September 4, 2013 16:31
-
-
Save stanBienaives/6439472 to your computer and use it in GitHub Desktop.
Git hook to prevent unwanted Gemfile and Gemfile.lock to be commited
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/sh | |
| # | |
| # This script is triggered before every commit | |
| # It raises an alert when Gemfile or Gemfile.lock has been modified. | |
| # This is usefull when using localy a gem that must be included in Gemfile ( a degugger for instance). | |
| # To enable this hook, rename this file to "pre-commit" and add it to .git/hooks/ | |
| # of C/P the following block in your existing .git/hooks/pre-commit | |
| #IMPORTANT - for the hook to be active run: | |
| # chmod +x .git/hooks/pre-commit | |
| #enable user input | |
| exec < /dev/tty | |
| # check if Gemfile is in index | |
| if [ $(git diff --cached | grep -c Gemfile) -gt 0 ]; then | |
| git status | |
| read -p "Gemfile has been modified. Are you sure you want to commit Gemfile?(Y/n)" commit | |
| if [ "$commit" = "Y" ]; then | |
| echo "Such a badass!" | |
| else | |
| echo "Checkouting Gemfile and Gemfile.lock" | |
| git reset Gemfile* | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment