Skip to content

Instantly share code, notes, and snippets.

@holyjak
Created March 27, 2015 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save holyjak/53e9b514112e9dc1b2f5 to your computer and use it in GitHub Desktop.
Save holyjak/53e9b514112e9dc1b2f5 to your computer and use it in GitHub Desktop.
Git pre-commit hook that fails for changes introducing Jest/Jasmine's exclusive tests using "it.only"
#!/bin/sh
# A git pre-commit hook that verifies that the change does not introduce
# the use of a Jest/Jasmine exclusive test via 'it.only(..)', which would
# prevent most other tests from being run without any clear indication thereof
# Redirect output to stderr.
exec 1>&2
ADDED_IT_ONLY=$(git diff -U0 --cached -S"(\W|^)it\.only\s+?\(" --pickaxe-regex | egrep "(^\+.*it.only)|\+{3}")
if [ -n "$ADDED_IT_ONLY" ]; then
echo "PRE-COMIT CHECK FAILED: You have added calls to it.only(..) thus preventing other tests from running, please fix: $ADDED_IT_ONLY"
exit 1
fi
@lluft
Copy link

lluft commented Oct 15, 2015

Thanks a lot for that simple and elegant solution! I adapted it to my needs. Just out of curiosity the regex you are using doesn't "+?" behave the same way as "*" would have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment