Skip to content

Instantly share code, notes, and snippets.

@famanson
Forked from DerLobi/pre-commit
Created January 19, 2017 14:44
Show Gist options
  • Save famanson/5a9a6c58d96676cfb6119e058b644f00 to your computer and use it in GitHub Desktop.
Save famanson/5a9a6c58d96676cfb6119e058b644f00 to your computer and use it in GitHub Desktop.
Don't commit focused tests. Use this as a pre-commit hook and the commit won't succeed if you have staged changes that contain `fdescribe`, `fcontext`, `fit`, `fspecify` or `fexample`. Copy this file as `pre-commit` into the `.git/hooks` folder of your repository (create it if neccessary) and chmod +x the file.
#!/bin/sh
#
# This pre-commit hook looks for `fdescribe`, `fcontext`, `fit`, `fspecify` and `fexample` in the
# staged files and exits with an error code of 1 if there are such changes.
#
STATUS=0
DESCRIBEFILES=$(git diff --staged -G"^\s*fdescribe\(" --name-only | wc -l)
if [ $DESCRIBEFILES -gt 0 ]
then
echo "You forgot to remove a fdescribe in the following files:"
git diff --staged --name-only -G"^\s*fdescribe\("
echo ""
STATUS=1
fi
CONTEXTFILES=$(git diff --staged -G"^\s*fcontext\(" --name-only | wc -l)
if [ $CONTEXTFILES -gt 0 ]
then
echo "You forgot to remove a fcontext in the following files:"
git diff --staged --name-only -G"^\s*fcontext\("
echo ""
STATUS=1
fi
ITFILES=$(git diff --staged -G"^\s*fit\(" --name-only | wc -l)
if [ $ITFILES -gt 0 ]
then
echo "You forgot to remove a fit in the following files:"
git diff --staged --name-only -G"^\s*fit\("
echo ""
STATUS=1
fi
SPECIFYFILES=$(git diff --staged -G"^\s*fspecify\(" --name-only | wc -l)
if [ $SPECIFYFILES -gt 0 ]
then
echo "You forgot to remove a fspecify in the following files:"
git diff --staged --name-only -G"^\s*fspecify\("
echo ""
STATUS=1
fi
EXAMPLEFILES=$(git diff --staged -G"^\s*fexample\(" --name-only | wc -l)
if [ $EXAMPLEFILES -gt 0 ]
then
echo "You forgot to remove a fexample in the following files:"
git diff --staged --name-only -G"^\s*fexample\("
echo ""
STATUS=1
fi
exit $STATUS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment