Skip to content

Instantly share code, notes, and snippets.

@ebdrup
Last active December 17, 2015 19:38
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 ebdrup/5661367 to your computer and use it in GitHub Desktop.
Save ebdrup/5661367 to your computer and use it in GitHub Desktop.
Setting up .bashrc to run tests with npm test before git push.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment