Skip to content

Instantly share code, notes, and snippets.

@DevWouter
Created July 5, 2019 09:03
Show Gist options
  • Save DevWouter/b461d71b9484f9b79d03abb50d42eea4 to your computer and use it in GitHub Desktop.
Save DevWouter/b461d71b9484f9b79d03abb50d42eea4 to your computer and use it in GitHub Desktop.
Prevent fit/fdescribe in ts files
#!/bin/sh
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# uncomment next line for debugging, will print all expanded bash commands
# set -x
# Yes, if you put "fdescribe" in a comment block, this will still abort the
# commit and you're also an asshole.
# move to top level of git repo
cd `git rev-parse --show-toplevel`
branch=`git rev-parse --abbrev-ref HEAD`
changedFiles=`git diff $branch --name-only -G"fdescribe|fit|describe\.only|it\.only|debugger"`
if [ -n "$changedFiles" ]
then
matchesFound=`git diff $branch --name-only -G"fdescribe|fit|describe\.only|it\.only|debugger" | grep "\.ts$" | xargs grep -Hn --color=always -C 3 "fdescribe\|fit\|describe\.only\|it\.only\|debugger"`
if [ -n "$matchesFound" ]
then
echo "Abort commit because: test files contain fit and/or fdescribe"
echo ""
echo "$matchesFound"
echo ""
echo "To ignore warning and continue, use"
echo ""
echo " git commit --no-verify"
echo ""
# move back to original working directory
cd -
exit 1
fi
fi
# move back to original working directory
cd -
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment