Skip to content

Instantly share code, notes, and snippets.

@nikolaymatrosov
Created July 7, 2015 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolaymatrosov/e78672a17ab45a58b882 to your computer and use it in GitHub Desktop.
Save nikolaymatrosov/e78672a17ab45a58b882 to your computer and use it in GitHub Desktop.
Pre-commit hook (check for forgotten `only`, run client tests only on client code changes)
#!/bin/sh
SRC=$(git rev-parse --show-toplevel)/src/client
#==========================================================
# Check if I forgot to remove 'only' keyword from tests.
# To make sure that before commit run all tests
only=`grep -c -h -r --include "*.spec.js" -E "(describe|it)\.only" $SRC/src | awk -F ':' '{x +=$0}; END {print x}'`
if (( $((only)) > 0 ))
then
echo 'Remove ONLY from tests.'
# Output list of found only entries
grep -r -n --include "*.spec.js" -E "(describe|it)\.only" $SRC/src
exit 1
fi
#==========================================================
ch=`git diff --cached --name-only --diff-filter=ACM | grep 'src/client' -c`
if (( $((ch)) > 0 ))
then
echo "client"
gulp pre-commit --stdio inherit --cwd $SRC
else
echo "Server only. No pre-commit hook"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment