zlacker

[parent] [thread] 4 comments
1. teaear+(OP)[view] [source] 2026-02-03 20:11:18
It doesn’t seem like this solves the main issues with pre-commit hooks. They are broken by design. Just to name 2, they run during rebase and aren’t compatible with commits that leave unstaged files in your tree.
replies(2): >>bradle+Ar >>tomjak+Hv
2. bradle+Ar[view] [source] 2026-02-03 22:31:14
>>teaear+(OP)
I leave unstaged files all the time, not sure what you mean.
replies(1): >>teaear+k71
3. tomjak+Hv[view] [source] 2026-02-03 22:52:01
>>teaear+(OP)
> they … aren’t compatible with commits that leave unstaged files in your tree.

It's a little surprising that git doesn't pass pre-commit hooks any information, like a list of which files were changed in the soon-to-be-made commit. git does so for pre-push, where it writes to a hook's stdin some information about the refs and remotes involved in the push.

I wonder if many pre-commit hooks, like the kind which run formatters, would be better off as `clean` filters, which run on files when they are staged. The filter mechanism makes it easier to apply just to the files which were changed. In the git docs, they even use a formatter (`indent`) as an example.

https://git-scm.com/book/ms/v2/Customizing-Git-Git-Attribute...

◧◩
4. teaear+k71[view] [source] [discussion] 2026-02-04 02:56:07
>>bradle+Ar
Without extra shenanigans if you have an unstaged file that fails your test suite then pre-commit will reject your commit even if the staged files are error free.
replies(1): >>bradle+ID4
◧◩◪
5. bradle+ID4[view] [source] [discussion] 2026-02-05 01:25:58
>>teaear+k71
Our stuff is configured to only run on staged files.
[go to top]