Git:在推送到本地或远程主控之前强制测试

Ale*_* M. 3 ruby git testing rspec ruby-on-rails

如果测试(rspec)失败,有没有办法让 git 拒绝提交到本地或推送到远程主控?谢谢。

nTr*_*aum 5

使用执行的 git pre commit hook rake spec(取自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
Run Code Online (Sandbox Code Playgroud)