title: Commit in git only if tests pass
body: <p>I've recently started using git, and also begun unit testing (using Python's <code>unittest</code> module). I'd like to run my tests each time I commit, and only commit if they pass.</p>
  
  <p>I'm guessing I need to use <code>pre-commit</code> in <code>/hooks</code>, and I've managed to make it run the tests, but I can't seem to find a way to stop the commit if they tests fail. I'm running the tests with <code>make test</code>, which in turn is running <code>python3.1 foo.py --test</code>. It seems like I don't get a different exit condition whether the tests pass or fail, but I may be looking in the wrong place.</p>
  
  <p><strong>Edit:</strong> Is this something uncommon that I want to do here? I would have thought it was a common requirement...</p>
  
  <p><strong>Edit2:</strong> Just in case people can't be bothered to read the comments, the problem was that <code>unittest.TextTestRunner</code> doesn't exit with non-zero status, whether the test suite is successful or not. To catch it, I did:</p>
  
  <pre><code>result = runner.run(allTests)
  if not result.wasSuccessful():
      sys.exit(1)
  </code></pre>