Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would check to make sure that each step of the way, your script returns a non-zero exit code on failure. Check to see if your <code>python3.1 foo.py --test</code> returns a non-zero exit code if a test fails. Check to make sure your <code>make test</code> command returns a non-zero exit code. And finally, check that your <code>pre-commit</code> hook itself returns a non-zero exit code on failure.</p> <p>You can check for a non-zero exit code by adding <code>|| echo $?</code> to the end of a command; that will print out the exit code if the command failed.</p> <p>The following example works for me (I'm redirecting stderr to <code>/dev/null</code> to avoid including too much extraneous output here):</p> <pre><code>$ python3.1 test.py 2&gt;/dev/null || echo $? 1 $ make test 2&gt;/dev/null || echo $? python3.1 test.py 2 $ .git/hooks/pre-commit 2&gt;/dev/null || echo $? python3.1 test.py 1 </code></pre> <p><strong><code>test.py</code></strong>:</p> <pre><code>import unittest class TestFailure(unittest.TestCase): def testFail(self): assert(False) if __name__ == '__main__': unittest.main() </code></pre> <p><strong><code>Makefile</code></strong>:</p> <pre><code>test: python3.1 test.py </code></pre> <p><strong><code>.git/hooks/pre-commit</code></strong>:</p> <pre><code>#!/bin/sh make test || exit 1 </code></pre> <p>Note the <code>|| exit 1</code>. This isn't necessary if <code>make test</code> is the last command in the hook, as the exit status of the last command will be the exit status of the script. But if you have later checks in your <code>pre-commit</code> hook, then you need to make sure you exit with an error; otherwise, a successful command at the end of the hook will cause your script to exit with a status of <code>0</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload