Created
February 7, 2018 04:04
-
-
Save wisetara/abbb15faa32c478d831766afb100c589 to your computer and use it in GitHub Desktop.
pre-commit.sh
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/sh | |
# Git pre-commit hook that prevents accidentally committing things that shouldn't be, like: | |
# | |
# * ":focus", used with RSpec/Guard | |
# * "show_page", used to debug request specs | |
# * "console.log" or "console.debug", used in JavaScript debugging | |
# * "DO NOT COMMIT!" comments | |
# | |
# Modify the regexps to suit your needs. The error message shows the full regexp match, | |
# or just the first capture group, if there is one. | |
# | |
# To bypass this commit hook (and others), perhaps when defining ":focus" or "show_page" | |
# for the first time, commit with the "--no-verify" option. | |
# | |
# Partially written by Henrik Nyh <http://henrik.nyh.se> 2011-10-08 under the MIT License. | |
# And then I used Will DeWind and Eric Thompson's input. And then I did some things. | |
# | |
# | |
# Install: | |
# | |
# * Save this bad boy to your project | |
# * ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit | |
FILES='(js|css|rb|hbs|scss)' | |
FORBIDDEN = '(\{\{debugger.*|\{\{console.*|debugger|puts|binding\.pry|console\.log|console\.debug)' | |
GREP_COLOR='4;5;37;41' | |
if [[ $(git diff --cached --name-only | grep -E $FILES) ]]; then | |
git diff --cached --name-only | grep -E $FILES | \ | |
xargs grep --color --with-filename -n -E $FORBIDDEN && \ | |
echo "Looks like you are trying to commit something you shouldn't." | |
echo "Please fix your diff, or run 'git commit --no-verify' to skip this check, if you must." && \ | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code doesn't actually check for "DO NOT COMMIT"