Created
October 4, 2018 13:56
-
-
Save maanavshah/d0e5960c7c4ec48b757f92104b9f6c7e to your computer and use it in GitHub Desktop.
Pre-commit hook to avoid debugger commands - Ruby
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
# This script verifies if a list of "blacklist" words are presented in the files you are intended to commit such console | |
# output, debugging information or keys/tokens/passwords | |
# Instructions: | |
# Put this file into your .git/hooks folder and set as executable (chmod +x pre-commit) | |
# If you want to skip the hook just add the --no-verify: git commit --no-verify | |
# --------------------------------------------- | |
#!/bin/sh | |
# Modify this | |
# LIST='list\|of\|words\|splitted\|by\|slash\|and\|pipe' | |
LIST="byebug\|debugger\|binding.pry" | |
if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
for FILE in `git diff-index --name-status --cached $against -- | cut -c3-` ; do | |
# Check if the file contains one of the words in LIST | |
if grep -w $LIST $FILE; then | |
echo $FILE." has one of the word you don't want to commit. Please remove it" | |
exit 1 | |
fi | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Must be on the first line of the file. Otherwise, you'd get
error: cannot spawn .git/hooks/pre-commit: No such file or directory
when trying to commit something.I'd leave this as
against=$(git hash-object -t tree /dev/null)
. You can see this line in the examples.