gredr•

I always figured hooks in git were kinda a "worst practice". Because you can't enforce others' use of them on their system, and these kinds of hooks in general were always bad in all source control, because you can't guarantee that everyone who might use them has a compatible environment.

Are git hooks actually commonly used?

1

they haven't been commonly used yet because, as you said, you can't get everyone to use the same hooks / versions of hooks. But that's where trunk comes into play - you can configure hooks for your repo, and if devs are using any part of trunk it automatically syncs their hooks to the hooks configured in the repo. Hooks can be really powerful. Even doing things like autoformatting the files you changed pre-commit without having to do anything is really slick / saves time.

1
gredr•

Trunk might sync the hooks... if I'm using trunk. And the right version of trunk. And I have the right version of Python. And I'm on Linux. And my Rust compiler is up-to-date. And I have some arbitrary Node tool installed globally. And I use rbenv instead of rvm. And...

2

Ya you do need to be using trunk - but trunk actually manages runtime versions (python etc) for linux|mac completely sandboxed hermetically. For example if your hooks, or other 'trunk actions', are python scripts, trunk will guarantee all users in your repo are using both the same hooks and the same version of python, without affecting the rest of their environments. Even if you have some random version of python installed locally, it doesn't matter. Also the way trunk manages versions of itself is neat - you pin a version in your repo and all users are guaranteed to run that version of it. When they run trunk in that repo, it'll check the pinned version in the repo's trunk.yaml and download+run the right version for the repo. The problems you're describing are real, annoying, and screw teams up - Trunk tackles those issues

1
gredr•

But trunk can't manage the things that the hooks do. The hooks have to be written so they work everywhere, and that's the hard part. Or, at least, it's a hard part, hard enough that hooks in systems like git just aren't used all that much.

If I want to enforce code formatting, I'll just reject any PRs that are badly formatted.

1