git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 0/7] Multiple hook support

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
May 14, 2019, 01:59 UTC
Message-ID
<20190514015928.GG7458@genre.crustytoothpaste.net>
In-Reply-To
<20190514004920.GB136746@google.com>
On Mon, May 13, 2019 at 05:51:01PM -0700, Jonathan Nieder wrote:
Show 14 quoted lines
> Hi,
> 
> brian m. carlson wrote:
> 
> > I've thought a lot about the discussion over whether this series should
> > use the configuration as the source for multiple hooks. Ultimately, I've
> > come to the decision that it's not a good idea. Even adopting the empty
> > entry as a reset marker, the fact that inheritance in the configuration
> > is in-order and can't be easily modified means that it's not likely to
> > be very useful, but it is likely to be quite surprising for the average
> > user.
> 
> Can we discuss this some more?  What would it take to make it likely
> to be useful in your view?

There are two aspects here which I think are worth discussing. Let's discuss the inheritance issue first.

Order with multiple hooks matters. The best hook as an example for this is prepare-commit-msg. If I have a hook which I want to run on every repository, such as a hook that inserts some sort of ID (bug tracker, Gerrit, etc.), that hook, due to inheritance, *has* to be first, before any other prepare-commit-msg hooks. If I want a hook that runs before it, perhaps because a particular repository needs a different configuration, I have to wipe the list and insert both hooks. I'm now maintaining two separate locations for the command lines instead of just inserting a symlink to the global hook and dropping a new hook before it.

I don't think there's a good way to make it easier unless we radically customize the way configuration is done. I don't doubt that there are a small number of configurations where the inheritance behavior is fine—I believe GitHub's backend is one of them—but overall I think it's hard to reason about and customize.

The second issue here is that it's surprising. Users don't know how to reset a configuration option because we don't have a consistent way to do that. Users will not expect for there to be multiple ways to set hooks. Users will also not expect that their hooks in their configuration aren't run if there are hooks in .git/hooks. Tooling that has so far used .git/hooks will compete with users' global configuration options, which I guarantee you will be a surprise for users using older versions of tools.

The new behavior, which puts everything in the same directory (.git/hooks) is much easier to reason about. I think we're obligated to consider the experience for the average end user, who may not be intimately familiar with how Git works but still needs to use it to get work done.

It also provides a convenient place for hooks to live, which a config-based option doesn't. We'll need to invoke things using /bin/sh, so will they all have to live in PATH? What about one-offs that don't really belong in PATH?

Show 10 quoted lines
> > I think a solution that sticks with the existing model and builds
> > off a design used by other systems people are familiar with, like cron
> > and run-parts, is going to be a better choice. Moreover, this is the
> > design that people have already built with outside tooling, which is a
> > further argument in favor of it.
> 
> To be clear, the main advantage I see for config versus the .git/hooks
> model is that with the config model, a user doesn't have to search
> throughout the filesystem for .git/hooks directories to update when a
> hook is broken.

I agree this is an advantage if they don't hit the ordering issue. I think a lot of the common use cases where this approach has benefits can be handled well with core.hooksPath and hooks that can turn themselves on or off depending on the repository config.

What might be an interesting approach that would address these concerns is a core.globalHooks[0] option that points to a set (or sets, depending) of multiple-hook directories. We then enumerate hooks in sort order, considering both the global and the local directories as one unit, perhaps with some way of disabling hooks. I'm not planning on working on this myself, but I wouldn't be opposed to seeing someone else work on it.

[0] Better name suggestions are, of course, welcome.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Jonathan NiederNext: Jonathan Nieder
Message 29 of 34 in “Multiple hook support”
  1. 0/7 Multiple hook supportbrian m. carlson, May 14, 2019
  2. 1/7 run-command: add preliminary support for multiple hooksbrian m. carlson, May 14, 2019
  3. Duy NguyenMay 14, 2019
  4. brian m. carlsonMay 15, 2019
  5. brian m. carlsonMay 29, 2019
  6. Johannes SchindelinMay 14, 2019
  7. brian m. carlsonMay 15, 2019
  8. Johannes SixtMay 16, 2019
  9. Johannes SchindelinMay 17, 2019
  10. 2/7 builtin/receive-pack: add support for multiple hooksbrian m. carlson, May 14, 2019
  11. 3/7 rebase: add support for multiple hooksbrian m. carlson, May 14, 2019
  12. Duy NguyenMay 14, 2019
  13. Johannes SixtMay 14, 2019
  14. brian m. carlsonMay 15, 2019
  15. Duy NguyenMay 16, 2019
  16. 3/7 sequencer: add support for multiple hooksbrian m. carlson, May 14, 2019
  17. 4/7 builtin/worktree: add support for multiple post-checkout hooksbrian m. carlson, May 14, 2019
  18. 5/7 transport: add support for multiple pre-push hooksbrian m. carlson, May 14, 2019
  19. 6/7 config: allow configuration of multiple hook error behaviorbrian m. carlson, May 14, 2019
  20. Duy NguyenMay 14, 2019
  21. brian m. carlsonMay 15, 2019
  22. Jeff KingMay 16, 2019
  23. Jeff KingMay 16, 2019
  24. brian m. carlsonMay 16, 2019
  25. Jeff KingMay 16, 2019
  26. 7/7 docs: document multiple hooksbrian m. carlson, May 14, 2019
  27. Duy NguyenMay 14, 2019
  28. Jonathan NiederMay 14, 2019
  29. brian m. carlsonMay 14, 2019
  30. Jonathan NiederMay 14, 2019
  31. brian m. carlsonMay 16, 2019
  32. Jonathan NiederMay 16, 2019
  33. Jeff KingMay 16, 2019
  34. Duy NguyenMay 14, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.