Pre-commit hooks aren't a good place to test
Message from 2022
This post is pretty old! Opinions and technical information in it are almost certainly oudated. Commands and configurations will probably not work. Consider the age of the content before putting any of it into practice.
Inspired by reading “Slaying dragons with git, bash, and ruby” by Glenn Gillen.
I don’t use pre-commit hooks to make sure my code is nice and clean, to make sure all my tests pass, or to make sure there’s no debugging stuff left; there’s no place for it in my workflow.
Red, Green, Refactor is what I try to do, with a commit after each step. This way, if I decide that I hate the current test, implementation, or refactoring, I can quickly roll it back without hitting “undo” in different files. As a side effect, I’m constantly committing with failing tests.
If you need a little digital nanny to keep you from breaking the build, try “autotest,” (or a similar automatic-testing tool) and just make sure it comes up green before you push or send a pull request.