threads / discuss / 61538

Inaccurate documentation for core.hooksPath?

Subject: Inaccurate documentation for core.hooksPath?

## tl;dr

2 messages between May 23, 2024 and May 29, 2024.

replies: 1people: 2as markdown or json

Mark Boyd - Q2AAAA· May 23, 2024, 19:36 UTC · lore
Hello,

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?

Thanks, Mark

Jeff King· May 29, 2024, 10:45 UTC · re: Mark Boyd - Q2AAAA · lore

Re: Inaccurate documentation for core.hooksPath?

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

← back to recent threads