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

Re: Inaccurate documentation for core.hooksPath?

From
Jeff King <peff@peff.net>
Date
May 29, 2024, 10:45 UTC
Message-ID
<20240529104515.GG1098944@coredump.intra.peff.net>
In-Reply-To
<CABBKgan9hLme+9WTNNVrZXxqO4-VRGiC3RLQgfKFUHAy3QZvDA@mail.gmail.com>
On Thu, May 23, 2024 at 03:36:49PM -0400, Mark Boyd - Q2AAAA wrote:
Show 11 quoted lines
> This documentation says that git only looks for hooks in the
> configured core.hooksPath:
> https://github.com/git/git/blob/master/Documentation/config/core.txt#L499-L504
> 
> However, in my testing, git will run both hooks located in the
> core.hooksPath directory and in the local git repo hooks directory
> (.git/hooks by default). Observation of this behavior is documented in
> https://github.com/cloud-gov/caulking/issues/37.
> 
> Is the behavior I'm seeing the actually expected behavior of git? Or
> are we somehow relying on an edge-case or buggy behavior?

Can you show us a more complete example that runs both hooks? I didn't see in that issue where it was clear that both were being run. When I try to make a minimal example, like this:

-- >8 -- git init -q repo cd repo

echo 'echo >&2 running in-repo hook' >.git/hooks/pre-commit chmod +x .git/hooks/pre-commit git commit --allow-empty -m "should have run in-repo hook"

git config core.hookspath $PWD git commit --allow-empty -m "should have run no hook"

echo 'echo >&2 running external hook' >pre-commit chmod +x pre-commit git commit --allow-empty -m "should have run external hook" -- >8 --

I get the expected output:
  running in-repo hook
  [main (root-commit) 22a8fd5] should have run in-repo hook
  [main ebc5524] should have run no hook
  running external hook
  [main 5ca6b75] should have run external hook

Looking at the code, everything is as I'd expect. Certainly there could be a bug where it finds the wrong path, but I don't see how it could ever run _two_ hooks.

-Peff
Previous: Mark Boyd - Q2AAAA
Message 2 of 2 in “Inaccurate documentation for core.hooksPath?”
  1. Mark Boyd - Q2AAAAMay 23, 2024
  2. Jeff KingMay 29, 2024

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.