pre-commit hooks are fundamentally broken

51 points by calvin


olliej

To me this honestly just seems like misuse of the hooks? Why would you want the act of committing a diff to change the diff? In any case - formatting or otherwise?

The only way that I have ever seen pre-commit hooks is to simply prevent a commit - making a change to the commit and then committing something that was likely not read by the author, and definitely not the reviewer is not something I would ever have considered. I would consider all the other problems that post talks about stem from the decision to try to automate changes to the patch that was written and reviewed, not inherent to the pre-commit hook mechanism.

I get the desire to automate trivial tasks, but running a formatter prior to pushing is not hard and means the you and the reviewer have actually read what the real commit was, which seems vastly superior to potentially arbitrary changes.

For rust this isn't an obvious problem, but for other languages bugs in "reasonable" formatting changes could legitimately create bugs - reindentation of code in indentation contexts, adding or removing braces according to existing style rules, etc. In general there's not likely to be a bug in such tooling, but as the article demonstrated their initial version would have committed a massive unrelated change had the commit-hook just worked immediately.

I get that their are problems with pre-commit hooks, but labelling them fundamentally broken for what is, as far as I'm aware, not an intended use case does not seem reasonable.

It's not a matter of which tree, etc the hook/diff/whatever is running on, as I see it problem here is thatwhat they're trying to use the hooks for does not seem reasonable in the first place?

Maybe I'm wrong and other people do have such systems in place, but if I were a reviewer of code, and the pushed PR was different from what I reviewed I would not be particularly happy, unless they were specific changes I had preemptively approved.