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

RFC: Supporting .git/hooks/$NAME.d/* && /etc/git/hooks/$NAME.d/*

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 22, 2016, 23:51 UTC
Message-ID
<CACBZZX6j6q2DUN_Z-Pnent1u714dVNPFBrL_PiEQyLmCzLUVxg@mail.gmail.com>

On Sat, Apr 23, 2016 at 1:33 AM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

> Change the hardcoded lookup for .git/hooks/* to optionally lookup in
> $(git config core.hooksDirectory)/* instead if that config key is set.

I think this'll do for my use-case, but I started with a rather more ambitious patch that I could forsee not finishing today.

I wanted to support executing e.g. the pre-commit hook, in order, from any of:
    .git/hooks/pre-commit
    .git/hooks/pre-commit.d/*
     [We could add some ~-wide path here I guess...]
     /etc/git/hooks/pre-commit
     /etc/git/hooks/pre-commit.d/*
Where the * would be resolved in glob() order.

The motivation was solving the use-case I'm solving with core.hooksDirectory, perhaps with a config variable to set whether you wanted to skip per-repo or system-wide hooks, but also having something more general.

The reason for supporting the *.d directories was that I spotted a lot of hooks people had hacked up at work using the pee(1) command[1] to run sequences of other unrelated hook commands.

Just symlinking stuff is simpler and more portable if we do the work in git.git once. We'd run The pee(1) command also doesn't quit on the first command that returns nonzero, which would make sense e.g. for pre-commit hooks.

I have it working for the hooks that use the simple run_hook_ve() interface, but the ones that have to e.g. pass input on stdin just find_hook() directly & do a custom run_command(), so all of those callsites would have to be patched and/or I'd have to hack up some custom callback mechanism.

1. http://manpages.ubuntu.com/manpages/xenial/en/man1/pee.1.html
Next: Junio C Hamano
Message 1 of 8 in “RFC: Supporting .git/hooks/$NAME.d/* && /etc/git/hooks/$NAME.d/*”
  1. Ævar Arnfjörð BjarmasonApr 22, 2016
  2. Junio C HamanoApr 25, 2016
  3. Ævar Arnfjörð BjarmasonApr 26, 2016
  4. Marc BranchaudApr 26, 2016
  5. Ævar Arnfjörð BjarmasonApr 26, 2016
  6. Christian CouderApr 26, 2016
  7. Marc BranchaudApr 26, 2016
  8. Junio C HamanoApr 26, 2016

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.