Commit in git only if tests pass

前端 未结 3 519
春和景丽
春和景丽 2020-12-13 00:24

I\'ve recently started using git, and also begun unit testing (using Python\'s unittest module). I\'d like to run my tests each time I commit, and only commit i

3条回答
  •  一整个雨季
    2020-12-13 00:47

    Could you parse the result of the python test session and make sure to exit your pre-commit hook with a non-zero status?

    The hook should exit with non-zero status after issuing an appropriate message if it wants to stop the commit.

    So if your python script does not return the appropriate status for any reason, you need to determine that status directly from the pre-commit hook script.
    That would ensure the commit does not go forward if the tests failed.
    (or you could call from the hook a python wrapper which would call the tests, and ensure a sys.exit(exit_status) according to the test results).

提交回复
热议问题