Git: forcing tests before pushing to local or remo

2020-07-25 02:46发布

问题:

Is there a way so that git refuses to commit to local or push to remote master if tests (rspec) are failing ? Thank you.

回答1:

Use a git pre commit hook which executes rake spec (taken from Tips for using a git pre-commit hook).

git stash -q --keep-index
`rake rspec`
RESULT=$?
git stash pop -q
[ $RESULT -ne 0 ] && exit 1
exit 0