News for hackers. Stuff that matters.
Re:Pre-commit hooks are fundamentally broken by nine_k on Saturday December 27, 2025 @04:12AM (#46400392)
A bit less enraged: pre-commit hooks should be pure functions. They must not mutate the files being committed. At best, they should generate a report. At worst, they could reject a commit (e.g. if it contains a private key file included by mistake).
Re:Pre-commit hooks are fundamentally broken by normie3000 on Saturday December 27, 2025 @04:26AM (#46400454)
> e.g. if it contains a private key file included by mistake

Thanks - this is the first example of a pre-commit hook that I can see value in.

Re:Pre-commit hooks are fundamentally broken by seba_dos1 on Saturday December 27, 2025 @09:01AM (#46401913)
Remember that such key will be copied into the repository on `git add` already and will stay there until garbage collected.
Re:Pre-commit hooks are fundamentally broken by normie3000 on Thursday January 01, 2026 @04:52PM (#46458463)
Thanks, good to keep in mind. Although presumably that means it's in my local repository. And it would have already been in my local filesystem anyway.
Re:Pre-commit hooks are fundamentally broken by Ferret7446 on Saturday December 27, 2025 @04:41AM (#46400520)
In my experience pre-commit hooks are most often used to generate a starting commit message.

To put it more bluntly, pre-commit hooks are pre-commit hooks, exactly what it says on the tin. Not linting hooks or checking hooks or content filters. Depending on what exactly you want to do, they may or may not be the best tool for the job.

To put it even more bluntly, if you are trying to enforce proper formatting, pre-commit hooks are absolutely the wrong tool for the job, as hooks are trivially bypassable, and not shared when cloning a repo, by design.

Re:Pre-commit hooks are fundamentally broken by p_wood on Saturday December 27, 2025 @01:39PM (#46404053)
> In my experience pre-commit hooks are most often used to generate a starting commit message.

The `prepare-commit-msg` hook is a better place to do that as it gives the hook some context about the commit (is the user amending an existing commit etc.)

> To put it even more bluntly, if you are trying to enforce proper formatting, pre-commit hooks are absolutely the wrong tool for the job, as hooks are trivially bypassable, and not shared when cloning a repo, by design.

They aren't a substitute for server post-receive hooks but they do help avoid having pushes rejected by the server.