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

Re: [PATCH] git: add --no-hooks global option

From
Derrick Stolee <stolee@gmail.com>
Date
Apr 4, 2025, 00:40 UTC
Message-ID
<c1312cb3-dd2b-4b04-8c6f-2d787125448d@gmail.com>
In-Reply-To
<Z-8Rxy4IK5EHKzLW@tapette.crustytoothpaste.net>
On 4/3/2025 6:55 PM, brian m. carlson wrote:
> On 2025-04-03 at 22:38:08, Derrick Stolee via GitGitGadget wrote:
>> From: Derrick Stolee <stolee@gmail.com>
Show 10 quoted lines
>> To that end, add a new --no-hooks global option to allow users to
>> disable hooks quickly. This option is modeled similarly to the
>> --no-advice option in b79deeb554 (advice: add --no-advice global option,
>> 2024-05-03). This uses a GIT_HOOKS environment variable to communicate
>> to subprocesses as well as making this a backwards-compatible way for
>> tools to signal that they want to disable hooks.
>>
>> The critical piece is that all hooks pass through run_hooks_opt() where
>> a static int will evaluate the environment variable and store that the
>> variable is initialized for faster repeated runs.
Show 9 quoted lines
>>     This is hopefully a helpful feature to more than just the experts I've
>>     been hearing from.
> 
> I think this is functionality that Jenkins wants because they've
> configured `core.hooksPath` to `/dev/null`, allegedly for security
> reasons.  Of course, enabling this feature will also break Git LFS, but
> in a less noticeable and detectable way (currently, Git LFS will fail on
> attempting to install hooks with that setting of `core.hooksPath`, which
> is at least noticeable).

I agree that some hooks are necessary for certain repositories to keep their data consistent. Another example is the pre- and post-command hooks that are in the microsoft/git fork that are necessary to avoid issues with the virtualization layer of VFS for Git. If a user disables those hooks during a command that changes the index, then they are going to have a bad time. But maybe they want to disable hooks because all they need is a 'git rev-parse HEAD' or similarly read-only operation.

Show 6 quoted lines
> I do think that in general certain types of hooks, such as pre-commit
> hooks, should absolutely be optional.  There are lots of reasons to
> commit WIP data that doesn't meet whatever standard and we shouldn't
> impede expert users from expert workflows, even if there are many fewer
> reasons to do things like bypass pushing Git LFS objects (which are
> important for integrity).
My intention is definitely more on the side of these optional hooks. 
Show 9 quoted lines
> So I can see the utility of this feature but I can also see how it can
> break lots of things when handled poorly.  Of course, we also have `git
> reset --hard` and there's lots of hand-wringing on Stack Overflow about
> having deleted important data, so we have some precedent for expert
> features that could break things badly.
> 
> I don't otherwise have a strong opinion either way, although I'd lean
> slightly in favour of this series.  I'd of course welcome other people's
> thoughts here.
Thank you for chiming in! I look forward to other thoughts and whetherthe warning in the docs should be strengthened.

Thanks, -Stolee

Previous: brian m. carlsonNext: Phillip Wood
Message 3 of 17 in “git: add --no-hooks global option”
  1. git: add --no-hooks global optionDerrick Stolee via GitGitGadget, Apr 3, 2025
  2. brian m. carlsonApr 3, 2025
  3. Derrick StoleeApr 4, 2025
  4. Phillip WoodApr 4, 2025
  5. Derrick StoleeApr 14, 2025
  6. Phillip WoodApr 16, 2025
  7. Junio C HamanoApr 16, 2025
  8. Derrick StoleeApr 16, 2025
  9. Lucas Seiki OshiroApr 14, 2025
  10. brian m. carlsonApr 14, 2025
  11. D. Ben KnobleApr 11, 2025
  12. docs: document core.hooksPath=/dev/nullDerrick Stolee via GitGitGadget, Apr 16, 2025
  13. Lucas Seiki OshiroApr 16, 2025
  14. Derrick StoleeApr 17, 2025
  15. brian m. carlsonApr 17, 2025
  16. Junio C HamanoApr 17, 2025
  17. Lucas Seiki OshiroApr 17, 2025

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.