Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Search changes, not entire index

Previously, we searched the entire index.  This meant that if e.g.
console.log appeared anywhere in the codebase (even if you didn't add
it), the pre-commit hook would fail.
  • Loading branch information...
commit 3267e5f6bfedc23fc4064d939739c38c1b5ecdc5 1 parent 6788664
@ithinkihaveacat authored
Showing with 14 additions and 3 deletions.
  1. +14 −3 hooks/pre-commit
View
17 hooks/pre-commit
@@ -1,11 +1,22 @@
#!/bin/sh
+# Configure via something like:
+#
+# $ git config --global hooks.preCommitRegexp 'var_dump|console\.log'
+
PAGER=""
-if git grep -q --cached rawlog ; then
- echo "# Error: attempt to commit rawlog"
+regexp=$(git config hooks.preCommitRegexp)
+
+if [ -z "$regexp" ]; then
+ exit 0
+fi
+
+if ! git diff-index --quiet --cached -G "$regexp" HEAD ; then
+ echo "# Error: commit adds text matching /$regexp/"
+ echo "# (use \"git commit --no-verify\" to force)"
echo "#"
- git grep --cached -C 3 rawlog | sed -e 's/^/# /'
+ git diff-index -U --cached -G "$regexp" HEAD | sed -e 's/^/# /'
exit 1
else
exit 0

0 comments on commit 3267e5f

Please sign in to comment.
Something went wrong with that request. Please try again.