iXNyNe
TTCTheo's Typesafe Cult
•Created by iXNyNe on 7/17/2024 in #questions
pre-commit and other git hooks
I do not disagree with Theo on the pre-commit topic.
I just watched today's pre-commit video https://www.youtube.com/watch?v=LL01pLjcR5s and coincidentally just yesterday I had rewatched one of his older videos on pre-commit https://www.youtube.com/watch?v=RAelLqnnOp0
I am all about CI/CD and use tools like GH actions a lot, but also admit I have work do do in some projects to build out better CI.
So why am I opening this thread?
In my head when I hear pre-commit hooks, I often mentally substitute that with "any kind of git hook" and want to talk about that. I wonder if anyone else conflates "any kind of git hook" in their head the way I do (or if I'm just off-base).
One of the ways I use git hooks that's actually relevant to Theo's video from today is to run
npm install
via https://github.com/thdk/package-changed?tab=readme-ov-file#use-git-hooks-to-run-package-changed-automatically with post-checkout
, post-merge
, and post-rebase
. To be specific about how this works (for those who haven't uses package-changed
) it checks if your package.json
(and optionally package-lock.json
) has changed by storing a hash and checking against that hash to determine if npm install
needs to run. This is relevant to what Theo mentions around the 7:50 mark in today's video. With this in place (assuming a clever dev hasn't /dev/null
'd husky) the problem of pulling new commits that include changes to dependencies for the most part goes away. It's not a substitute for CI by any means and shouldn't stop anyone from working. It's just meant to be a gentle assist.
So I'm curious what everyone here thinks of the above use case, and also would love to hear if there are any other good uses of git hooks that anyone likes, or even valid uses of pre-commit (aside from the secret scanning idea mentioned in the video).2 replies