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

Re: [PATCH 0/5] Multiple hook support

From
Bryan Turner <bturner@atlassian.com>
Date
Apr 24, 2019, 18:29 UTC
Message-ID
<CAGyf7-E2tf7hymOOUSAO6325NyyADWmmMjSRx87-UKVhQd-ufw@mail.gmail.com>
In-Reply-To
<87tvensu1a.fsf@evledraar.gmail.com>

On Wed, Apr 24, 2019 at 1:10 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 19 quoted lines
>
> On Wed, Apr 24 2019, brian m. carlson wrote:
>
> > Oftentimes, people want to use multiple of the same kind of hook. This
> > may be because software or a project they use requires a given hook, but
> > they would also like to have a custom hook, or because they're using
> > multiple pieces of software that both require involvement with the same
> > hook.
> >
> > This series introduces support for multiple hooks by using a ".d"
> > directory. For example, instead of using a single
> > ".git/hooks/post-checkout" file, you'd use multiple files within
> > ".git/hooks/post-checkout.d". This is the standard Unix paradigm for
> > multiple files and should be familiar to most people. Hooks are executed
> > in sorted order.
>
> I think it's interesting if people can chime in with current in-the-wild
> implementations of this.
>

Bitbucket Server also uses trampoline scripts for pre-receive and post-receive that loop over scripts in matching *.d directories and run them.

* It passes --template to "git init" (new repositories) and "git
clone" (forks) to have Git copy hook structure into place as part of
creating the repository.
* To avoid looping over thousands or tens of thousands of repositories
if those scripts need to change, the scripts put in place (both at the
pre-receive/post-receive level and for *.d/20_bitbucket_callback) are
essentially placeholders that use environment variables exported when
running "git http-backend" and "git receive-pack" to delegate to
helper scripts that actually do the work.
* The helper scripts only exist in one place, so they can easily be
updated if they need to change.
* When looping over *.d scripts, the helper script stops after the
first non-zero return.
On Tue, Apr 23, 2019 at 7:41 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
>
> One downside is that the transition from the old to the new world
> order becomes a bigger deal.  You could have been using a precursor
> of this series implemented entirely as a shell script
>
>         $ cat >.git/pre-commit <<\EOF
>         #!/bin/sh
>         for x in .git/pre-commit.d/*
>         do
>                 "$x" "$@" || exit 1
>         done
>         exit 0
>         EOF
>         $ chmod +x .git/pre-commit
>
> and with your approach, the user can keep using that set-up and then
> simply remove that single file once all the Git executables the user
> uses are natively aware of the multi-hook setup.  With "either a
> file or directory" approach, the transition would be removing the
> file *and* renaming pre-commit.d directory to pre-commit.
>

This would be true for Bitbucket Server, since its trampoline scripts are really simple: It could just delete them and let Git loop over the existing *.d directories itself, so the current approach offers a really straightforward upgrade path.

Of course, since Bitbucket Server supports a range of Git versions on the server, and for compatibility reasons the minimum is only raised in major version releases, it would likely be quite some time before that could happen; the minimum supported Git version would need this series to have landed in or before it. That's a big part of why Bitbucket Server doesn't use core.hooksPath; it's too new. (Bitbucket Server 6.0 raised the minimum Git version on the server to 2.11.0, so it's the first major series that could use core.hooksPath; Bitbucket Server 5.x supported back to Git 2.2.0, which doesn't have it.)

Best regards, Bryan Turner

Previous: Phillip WoodNext: Duy Nguyen
Message 46 of 51 in “Multiple hook support”
  1. 0/5 Multiple hook supportbrian m. carlson, Apr 24, 2019
  2. 1/5 run-command: add preliminary support for multiple hooksbrian m. carlson, Apr 24, 2019
  3. Junio C HamanoApr 24, 2019
  4. Johannes SixtApr 24, 2019
  5. Junio C HamanoApr 25, 2019
  6. Ævar Arnfjörð BjarmasonApr 25, 2019
  7. Junio C HamanoApr 25, 2019
  8. Johannes SixtApr 25, 2019
  9. brian m. carlsonApr 26, 2019
  10. Johannes SixtApr 26, 2019
  11. brian m. carlsonApr 24, 2019
  12. 2/5 builtin/receive-pack: add support for multiple hooksbrian m. carlson, Apr 24, 2019
  13. 3/5 sequencer: add support for multiple hooksbrian m. carlson, Apr 24, 2019
  14. Phillip WoodApr 24, 2019
  15. brian m. carlsonApr 24, 2019
  16. Phillip WoodApr 25, 2019
  17. 5/5 transport: add support for multiple pre-push hooksbrian m. carlson, Apr 24, 2019
  18. 4/5 builtin/worktree: add support for multiple post-checkout hooksbrian m. carlson, Apr 24, 2019
  19. Junio C HamanoApr 24, 2019
  20. brian m. carlsonApr 24, 2019
  21. Junio C HamanoApr 24, 2019
  22. Ævar Arnfjörð BjarmasonApr 24, 2019
  23. Jonathan NiederApr 24, 2019
  24. Ævar Arnfjörð BjarmasonApr 24, 2019
  25. Ævar Arnfjörð BjarmasonApr 24, 2019
  26. brian m. carlsonApr 24, 2019
  27. Jonathan NiederApr 24, 2019
  28. How to undo previously set configuration? (again)Ævar Arnfjörð Bjarmason, Apr 25, 2019
  29. Duy NguyenApr 25, 2019
  30. Ævar Arnfjörð BjarmasonApr 25, 2019
  31. Ævar Arnfjörð BjarmasonApr 26, 2019
  32. Jonathan NiederApr 25, 2019
  33. Barret RhodenApr 25, 2019
  34. Ævar Arnfjörð BjarmasonApr 25, 2019
  35. Ævar Arnfjörð BjarmasonApr 25, 2019
  36. Junio C HamanoApr 26, 2019
  37. Duy NguyenApr 26, 2019
  38. Jeff KingApr 30, 2019
  39. Duy NguyenMay 1, 2019
  40. Ævar Arnfjörð BjarmasonMay 1, 2019
  41. Duy NguyenMay 1, 2019
  42. Jeff KingMay 1, 2019
  43. Jeff KingMay 1, 2019
  44. Ævar Arnfjörð BjarmasonApr 24, 2019
  45. Phillip WoodApr 24, 2019
  46. Bryan TurnerApr 24, 2019
  47. Duy NguyenApr 24, 2019
  48. brian m. carlsonApr 24, 2019
  49. brian m. carlsonApr 24, 2019
  50. Duy NguyenApr 25, 2019
  51. Jeff KingApr 30, 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.