Github does not provide pre-receive hooks, so in order to ensure that all tests are run before a push is accepted, you should add the following to your %HOME%/.bashrc
file (node.js example - something similar can be done for .Net):
# begin: automatic run of tests
GIT_LOCATION=$(which git)
git () {
if [ "$1" == "push" ] && [ -f package.json ] ; then
if [[ "$*" == *\ --no-verify* ]] ; then
echo "skipping tests..."
# skip the testing and remove the custom --no-verify option before calling git
set -- $(echo "$@" | sed -e 's/ --no-verify//g')
else
echo "running tests..."
npm test || return 1
fi
fi
$GIT_LOCATION "$@"
}
# end: automatic run of tests
If you want to disable the tests you can add an extra parameter --no-verify
to git push
like this:
$ git push --no-verify