3

I want to add a pre-commit hook in git for windows such commit just succeed if all test pass and pylint does not return any warning. I execute those in the command line this way:

py.test
pylint mypackage

After some research I have come up with the following pre-commit bash file (only for the py.test part):

#!/bin/sh
py.test
RESULT=$?
git stash pop -q
[ $? -ne 0 ] && exit 1
[ $RESULT -ne 0 ] && exit 1
exit 0

It effectively aborts the commit and prints a No stash found message at the end. The problem is that when I solve the failing test, the commit does not succeed and it still prints No stash found.

How could I solve this, including also pylint checks?

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
  • This looks very odd, because you never do an initial `git stash save`. See this question and my answer, and beware of the stash bug: http://stackoverflow.com/q/20479794/1256452 – torek Nov 06 '15 at 09:43
  • I would suggest you to consider a `pre-push` hook instead... I would be very annoyed if every single commit would run the tests, as I commit often. – Bruno Oliveira Nov 07 '15 at 13:32
  • @BrunoOliveira, I also commit frequently, but this can depend on many factors (speed of tests, code size...). Time permitting I prefer early warnings. – jruizaranguren Nov 09 '15 at 08:55
  • did you run 'git add' again on fixed files ? – sax Nov 09 '15 at 14:39

0 Answers0