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 16, 2019, 00:42 UTC
Message-ID
<20190516004233.GO7458@genre.crustytoothpaste.net>
In-Reply-To
<20190514022653.GA34155@google.com>
On Mon, May 13, 2019 at 07:26:53PM -0700, Jonathan Nieder wrote:
Show 5 quoted lines
> brian m. carlson wrote:
> In other words, use the standard config convention for the set of
> hooks, and treat the order in which they are invoked as a separate
> question.  You could even use the hooks.d style alphabetical order
> convention.

If we're going to have named items in PATH, we do not want to have those items numbered.

Show 8 quoted lines
> [...]
> > 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.
> 
> I agree that it's underdocumented and underimplemented.  But I'm not
> aware of any other method that Git provides to reset a configuration
> item.  What is it inconsistent with?
Some options support it, and some don't.
Show 9 quoted lines
> >           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.
> 
> Indeed, in the long term I think we should remove the .git/hooks/
> mechanism entirely.

See, I don't. I like the current mechanism and don't want to get rid of it.

> In the shorter term, I think the kind of inconsistency you're referring
> to applies to hooks.d as well.

I think it's a lot easier to reason about adding a directory to the existing mechanism than adopting a dramatically new one. Users can easily understand that if there's a file, that the directory is ignored.

Also, this is the way that most other programs on Unix do this behavior, and I think that is a compelling argument for this design in and of itself. I think Unix has generally made the best decisions in operating system design, and I aim to emulate it as much as possible.

Show 7 quoted lines
> > 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?
> 
> This hasn't been a problem for remote helpers, merge drivers, etc in
> the past.  Why are hooks different?

Because they're often customized or installed via the repository itself. Some projects provide pre-commit hooks to run tests or such in a repository-specific way. Some people have one-off scripts that are appropriate for a repo but they don't want in tab-completion. Also, they may wrap a system command with helpful information, but that doesn't belong in PATH.

Git LFS, for example, installs hooks that warn the user if the command isn't installed, since it's a common misconfiguration and not pushing the LFS objects (via the pre-push hook) along with the Git objects is a common source of data loss. Uninstalling the tool (or not installing it if it's a shared repository) doesn't mean the hook still shouldn't be run.

Show 14 quoted lines
> > 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.
> 
> This sounds overflexible to me.  Because of that, I don't think it
> would end up as a default, so we wouldn't have a path to improving our
> security stature.
> 
> If I implement a config based multiple hooks feature with name based
> ordering, would that be useful to you?

One of my primary motivations for writing this series is because it's a requested feature in conjunction with Git LFS. We often get requests for features that are properly directed to Git itself, but because the issue comes up in conjunction with the use of Git LFS, folks report the issues to us. (Also, people don't like reporting issues to mailing lists.) I think it's a useful feature for others, though, judging by the multiple times it's come up.

I see the series that I'm proposing as easy to implement and work with using the existing tools and with other tools that use the existing hooks. It's a simple change of path. I anticipate there being more work to implement a config-based multiple hooks solution in various tools, and I expect it will be less intuitive and less discoverable. I can't provide definitive evidence for this, but my experience answering a lot of user questions on a daily basis leads me to believe that it's not the right way forward.

I'm not opposed to extending the config system to implement multiple hooks directories or add support for inheriting hooks, because that's a common thing that people want. I just don't think our config system is the right tool for specifying what commands to run, for the reasons I've specified.

I can't prevent you from writing a series that implements a config-based option, and if it's the solution the list wants, I'll go along with it, but it's not the solution I want to see personally or as a tooling implementer.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Jonathan NiederNext: Jonathan Nieder
Message 31 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.