Created
September 24, 2012 18:07
-
-
Save dcvezzani/3777359 to your computer and use it in GitHub Desktop.
pre-commit hook for Git on a system running OSX (Mac)
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 | |
if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
# put the first changeset hash value in your project here (I think) | |
against=facf87a3fa1c853a7dd8dde8cba32e1fc8fde3ea | |
fi | |
for FILE in `git diff-index --name-status $against -- | cut -c3-` ; do | |
# Check if the file contains 'debugger' | |
if [ "grep 'debugger' $FILE" ] | |
then | |
echo $FILE ' contains debugger!' | |
exit 1 | |
fi | |
done | |
exit |
If you add the --cached
flag to your git diff-index
call, it'll only run against files that are staged for commit, which is generally what I think you want.
On my system, if [ "grep 'debugger' $FILE" ]
always evaluates to true. Changing it to if grep -q 'debugger' "$FILE"
fixes that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On line 7, you'll need
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
instead. This is a magic hash present in all git repositories. Just google the hash and you'll see