8 comments

  • thomashabets213 minutes ago
    I feel like I found better git commands for this, that don&#x27;t have these problems. It&#x27;s not perfect, sure, but works for me.<p>The pre commit script (<a href="https:&#x2F;&#x2F;github.com&#x2F;ThomasHabets&#x2F;rustradio&#x2F;blob&#x2F;main&#x2F;extra&#x2F;pre-commit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ThomasHabets&#x2F;rustradio&#x2F;blob&#x2F;main&#x2F;extra&#x2F;pr...</a>) triggers my executor which sets up the pre commit environment like so: <a href="https:&#x2F;&#x2F;github.com&#x2F;ThomasHabets&#x2F;rustradio&#x2F;blob&#x2F;main&#x2F;tickbox&#x2F;precommit&#x2F;10-setup.sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ThomasHabets&#x2F;rustradio&#x2F;blob&#x2F;main&#x2F;tickbox&#x2F;...</a><p>I run this on every commit. Sure, I have probably gone overboard, but it has prevented problems, and I may be too picky about not having a broken HEAD. But if you want to contribute, you don&#x27;t have to run any pre commit. It&#x27;ll run on every PR too.<p>I don&#x27;t send myself PRs, so this works for me.<p>Of course I always welcome suggestions and critique on how to improve my workflow.<p>And least nothing is stateful (well, it caches build artefacts), and aside from &quot;cargo deny&quot; no external deps.
    • 000ooo0005 minutes ago
      Only a minor suggestion: git worktrees is a semi-recent addition that may be nicer than your git archive setup
  • lemonlime2275 minutes ago
    To bring up jujutsu, `jj fix` (<a href="https:&#x2F;&#x2F;docs.jj-vcs.dev&#x2F;latest&#x2F;cli-reference&#x2F;#jj-fix" rel="nofollow">https:&#x2F;&#x2F;docs.jj-vcs.dev&#x2F;latest&#x2F;cli-reference&#x2F;#jj-fix</a>) is a more refined way of ensuring formatting in commits. It runs a formatting command with the diff in stdin and uses the results printed to stdout. It can simplify merges and rebases history to ensure all your commits remain formatted (so if you enable a new formatting option, it can remove the need for a special format&#x2F;style fix commit in your mutable set). Hard to go back to pre-commit hooks after using jj fix (also hard to use git after using jj ;) ).
  • Simplita59 minutes ago
    I’ve seen similar issues once hooks start doing more than fast checks. The moment they become stateful or depend on external context, they stop being guardrails and start being a source of friction. In practice, keeping them boring and deterministic seems to matter more than catching everything early.
  • nrclark1 hour ago
    This was a really interesting read. I&#x27;d highly recommend it for anybody who&#x27;s setting up (or currently maintains) a pre-commit workflow for their developers.<p>I want to add one other note: in any large organization, some developers will use tools in ways nobody can predict. This includes Git. Don&#x27;t try to force any particular workflow, including mandatory or automatically-enabled hooks.<p>Instead, put what you want in an optional pre-push hook and also put it into an early CI&#x2F;CD step for your pull request checker. You&#x27;ll get the same end result but your fussiest developers will be happier.
    • eru8 minutes ago
      &gt; This includes Git. Don&#x27;t try to force any particular workflow, including mandatory or automatically-enabled hooks.<p>And with git, you can even make anything that happens on the dev machines mandatory.<p>Anything you want to be mandatory needs to go into your CI. Pre-commit and pre-push hooks are just there to lower CI churn, not to guarantee anything.<p>(With the exception of people accidentally pushing secrets. The CI is too late for that, and a pre-push hook is a good idea.)
      • normie30003 minutes ago
        &gt; with git, you can even make anything that happens on the dev machines mandatory<p>s&#x2F;can&#x2F;can&#x27;t?
    • Mic921 hour ago
      I can second that. If there are multiple commits: <a href="https:&#x2F;&#x2F;github.com&#x2F;tummychow&#x2F;git-absorb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tummychow&#x2F;git-absorb</a> is handy to add formatting changes into the right commit after commits already happened.
  • 000ooo00010 minutes ago
    Your hook can&#x27;t observe a simple env var, if you are stepping off the happy path of your workflow? E.g. `GIT_HOOK_BYEBYE` = early return in hook script. Article seems a little dramatic. If you write a pre-commit hook that is a pain in your own arse, how does that make them fundamentally broken?
  • tkzed491 hour ago
    Thank you. I don&#x27;t need to &quot;fix&quot; a commit before it ends up on a remote branch. Sometimes I expect a commit to pass checks and sometimes I don&#x27;t. Frankly, don&#x27;t even run pre-push hooks. Just run the checks in CI when I push. You&#x27;d better be doing that anyway before I&#x27;m allowed to push to a production branch, so stop breaking my git workflows and save me the time of running duplicate checks locally.<p>Also, if most developers are using one editor, configure that editor to run format and auto-fix lint errors. That probably cleans up the majority of unexpected CI failures.
    • eru7 minutes ago
      Pre-commit and pre-push hooks are something developers can voluntarily add (or enable) to shorten the latency until they get feedback: instead of the CI rejecting their PR, they can (optionally!) get a local message about it.<p>Otherwise, I agree, your project can not rely on any checks running on the dev machine with git.
  • nine_k15 minutes ago
    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).
    • normie30001 minute ago
      &gt; e.g. if it contains a private key file included by mistake<p>Thanks - this is the first example of a pre-commit hook that I can see value in.
  • badgersnake45 minutes ago
    Yep, all that and they’re also annoying. Version control tools are not supposed to argue - do what you’re told. If I messed up, the branch build will tell me.
    • thomashabets210 minutes ago
      Is that the difference between forced pre commits vs opt in? I don&#x27;t want to commit something that doesn&#x27;t build. If nothing else it makes future bisects annoying.<p>But if I intend to squash and merge, then who cares about intermediate state.