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

Re: [PATCH] hook: introduce the report hook for git-receive-pack(1)

From
Karthik Nayak <karthik.188@gmail.com>
Date
Aug 19, 2026, 12:11 UTC
Message-ID
<CAOLa=ZSN+h4TkZrqPPRNZ58Pyfamv9_tM=m7W8_RYhUU0p0q0w@mail.gmail.com>
In-Reply-To
<7dc975d2-324b-46a4-a389-9af96f4d5d57@app.fastmail.com>
"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:
Show 36 quoted lines
> On Tue, Aug 18, 2026, at 09:55, Karthik Nayak wrote:
>> When running 'git-receive-pack(1)', there is currently no way for the
>> server to intercept and modify the status report before it is sent back
>> to the client. This is useful for servers with custom logic that need
>> to transform or gate the report based on the outcome of external logic
>> post reference updates.
>>
>> Introduce a new 'report' hook which receives the pkt-line encoded
>> status report on stdin and whose stdout replaces the report sent to the
>> client. A non-zero exit status causes `receive-pack` to die and the
>> client to treat the push as failed.
>>
>> Similar to the 'proc-receive' hook, this does not use the config-based
>> hook infrastructure. That infrastructure is designed for parallelizable
>> notification hooks. As this hook is a bidirectional filter, it would
>> require significant modifications to that infrastructure and this hook
>> cannot be parallelized anyway.
>>
>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
>> ---
>> To give some context, we at GitLab are building a custom MVCC around
>> Git. Each git-push would initialize a new version which is then
>> committed as the default post some operations. These operations take
>> place after the reference transaction and based on the output status of
>> those operations, we want to propagate the status to the user. There
>> currently exists no good mechanism to do so.
>>
>> Having a report hook which allows us to modify the report being
>> propagated to the user, allows us to modify the report based on the
>> status of our MVCC commit phase.
>
> Personally I think understanding concrete things is easier than
> understanding general things. And discussing the concrete case in the
> commit message would help with that as well as provide the context for
> git-log(1) rather than just the people who have read these emails.
>

I was conflicted about it, since while it does provide some context, it doesn't apply to most usecases. I will add a little more context in the commit message.

Show 23 quoted lines
>> ---
>>  Documentation/githooks.adoc |  23 ++++++
>>  builtin/receive-pack.c      |  41 +++++++++++
>>  t/meson.build               |   1 +
>>  t/t5412-report-hook.sh      | 176 ++++++++++++++++++++++++++++++++++++++++++++
>>  4 files changed, 241 insertions(+)
>
> Should the git-receive-pack(1) doc be updated to mention that this hook
> exists? I don’t understand the setup here. The existing
> git-receive-pack(1) doc has sections for these hooks:
>
> • `update`
> • `pre-receive`
> • `post-receive`
> • `post-update`
>
> But not these:
>
> • `push-to-checkout`
> • `proc-receive`
>
> (referenced against githooks(5))
>

I didn't know about this. I wonder why we have two sources of truth for the same. As you see, it's already starting to diverge.

I will add both of them with links to githooks(5), but perhaps a cleanup there is in order. I would say making githooks(5) the canonical location with git-receive-pack(1) referencing it makes sense.

Show 25 quoted lines
>>
>> diff --git a/Documentation/githooks.adoc b/Documentation/githooks.adoc
>> index ed045940d1..7e6643ad89 100644
>> --- a/Documentation/githooks.adoc
>> +++ b/Documentation/githooks.adoc
>> @@ -527,6 +527,29 @@ The exit status of the hook is ignored for any
>> state except for the
>>  status will cause the transaction to be aborted. The hook will not be
>>  called with "aborted" state in that case.
>>
>> +report
>> +~~~~~~
>> +
>> +This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
>> +`git push` and updates reference(s) in its repository. It executes on
>> +the remote repository once after all refs have been updated, but before
>> +the status report is sent back to the client.
>> +
>> +The hook receives the pkt-line encoded status report on standard input
>
> Another naive question (I have never used any of this). Should this link
> to some gitprotocol-X(5) after `pkt-line` in order to have a link that
> explains what it is? I don’t see any mention of `pkt-line` on
> git-receive-pack(1) or a mention of a gitprotocol-X(5).
>

We could link to 'Documentation/gitprotocol-common.adoc', but I'm not sure if it is erring on the side of being too verbose. I'll leave it out since its already existing and assumed to be common knowledge for users of such hooks. But happy to add it in if others disagree :)

Show 17 quoted lines
>> +and its standard output replaces the report sent to the client. Any
>> +output written to standard error is forwarded to the client over the
>> +sideband channel and will appear as `remote:` lines on the client's
>> +terminal. To reject individual ref updates, rewrite the corresponding
>> +`ok` lines to `ng` lines in the output report (with an explanatory
>> +error string) and exit zero; standard error can accompany this to
>> +provide a human-readable explanation. A non-zero exit status causes
>> +`receive-pack` to die.
>> +
>> +Note that by the time this hook runs, all ref updates have already been
>> +applied to the repository. A non-zero exit causes the client to see the
>> +push as failed, but does *not* roll back any ref changes that were
>> +already committed server-side.
>
> To my naive eyes this description looks good and without any obvious
> errors (typos ;) ).
>
Thanks for reading through
Show 20 quoted lines
>> +
>>  push-to-checkout
>>  ~~~~~~~~~~~~~~~~
>>
>> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
>>[snip]
>> @@ -2592,6 +2630,9 @@ static void report_v2(struct command *commands,
>> const char *unpack_status)
>>  	}
>>  	packet_buf_flush(&buf);
>>
>> +	if (run_report_hook(&buf))
>> +		die("report hook failed");
>
> Okay, it seems typical for this command to use regular strings (not
> translated) for errors. Which makes sense given the application. There
> does seem to be translated error strings but one example is “refusing to
> update current branch”, which seems to be more of a non-bare, end-user
> error than a server error.
>

Yeah, since these are generally less user-facing (I say less because this can be propagated to the user, if the hook exists with a non-zero error code) I choose not to translate it. As you mentioned, this seems to be the way for such error messages.

Show 15 quoted lines
>> +
>>  	if (use_sideband)
>>  		send_sideband(1, 1, buf.buf, buf.len, use_sideband);
>>  	else
>>[snip]
>> diff --git a/t/t5412-report-hook.sh b/t/t5412-report-hook.sh
>>[snip]
>> +test_expect_success "no report hook, push succeeds" '
>> +	test_when_finished "rm -rf upstream" &&
>> +	test_when_finished "git -C workbench remote remove origin" &&
>
> This teardown routine is common to all the tests. Is it better style
> here to write it out compared to using a helper function (test code is
> different from “normal” code)?
>

Since tests are self-contained, I usually keep the teardowns within them if they're simple enough.

>> +	git init --bare upstream &&
>>[snip]
Previous: Kristoffer HaugsbakkNext: Kristoffer Haugsbakk
Message 4 of 98 in “hook: introduce the report hook for git-receive-pack(1)”
  1. hook: introduce the report hook for git-receive-pack(1)Karthik Nayak, Aug 18, 2026
  2. Junio C HamanoAug 18, 2026
  3. Kristoffer HaugsbakkAug 19, 2026
  4. Karthik NayakAug 19, 2026
  5. Kristoffer HaugsbakkAug 19, 2026
  6. Patrick SteinhardtAug 19, 2026
  7. Karthik NayakAug 19, 2026
  8. Patrick SteinhardtAug 19, 2026
  9. Karthik NayakAug 19, 2026
  10. Phillip WoodAug 20, 2026
  11. Junio C HamanoAug 20, 2026
  12. Karthik NayakAug 21, 2026
  13. hook: introduce the report hook for git-receive-pack(1)Karthik Nayak, Aug 21, 2026
  14. Patrick SteinhardtAug 21, 2026
  15. Karthik NayakAug 21, 2026
  16. Patrick SteinhardtAug 24, 2026
  17. Karthik NayakAug 24, 2026
  18. Junio C HamanoAug 21, 2026
  19. 0/3 hook: introduce the report hook for git-receive-pack(1)Karthik Nayak, Aug 24, 2026
  20. 1/3 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Aug 24, 2026
  21. 2/3 receive-pack: move message generation to separate functionKarthik Nayak, Aug 24, 2026
  22. 3/3 hook: introduce the report hook for git-receive-pack(1)Karthik Nayak, Aug 24, 2026
  23. Junio C HamanoAug 24, 2026
  24. Junio C HamanoAug 24, 2026
  25. Patrick SteinhardtAug 24, 2026
  26. Karthik NayakAug 26, 2026
  27. Junio C HamanoAug 26, 2026
  28. 0/3 hook: introduce the receive-report hookKarthik Nayak, Aug 26, 2026
  29. 1/3 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Aug 26, 2026
  30. Patrick SteinhardtAug 31, 2026
  31. Karthik NayakAug 31, 2026
  32. 2/3 receive-pack: move message generation to separate functionKarthik Nayak, Aug 26, 2026
  33. Patrick SteinhardtAug 31, 2026
  34. Karthik NayakAug 31, 2026
  35. 3/3 hook: introduce the receive-report hookKarthik Nayak, Aug 26, 2026
  36. Patrick SteinhardtAug 31, 2026
  37. 0/3 hook: introduce the receive-report hookKarthik Nayak, Sep 1, 2026
  38. 1/3 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Sep 1, 2026
  39. 2/3 receive-pack: move message generation to separate functionKarthik Nayak, Sep 1, 2026
  40. Junio C HamanoSep 1, 2026
  41. Karthik NayakSep 2, 2026
  42. 3/3 hook: introduce the receive-report hookKarthik Nayak, Sep 1, 2026
  43. Junio C HamanoSep 1, 2026
  44. Karthik NayakSep 2, 2026
  45. Junio C HamanoSep 2, 2026
  46. 0/4 hook: introduce the receive-report hookKarthik Nayak, Sep 3, 2026
  47. 1/4 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Sep 3, 2026
  48. 2/4 receive-pack: drop static variables to track report status versionKarthik Nayak, Sep 3, 2026
  49. Patrick SteinhardtSep 3, 2026
  50. Karthik NayakSep 3, 2026
  51. 3/4 receive-pack: move message generation to separate functionKarthik Nayak, Sep 3, 2026
  52. Patrick SteinhardtSep 3, 2026
  53. Karthik NayakSep 3, 2026
  54. 4/4 hook: introduce the receive-report hookKarthik Nayak, Sep 3, 2026
  55. Patrick SteinhardtSep 3, 2026
  56. Karthik NayakSep 3, 2026
  57. 0/4 hook: introduce the receive-report hookKarthik Nayak, Sep 4, 2026
  58. 1/4 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Sep 4, 2026
  59. 2/4 receive-pack: drop static variables to track report status versionKarthik Nayak, Sep 4, 2026
  60. Junio C HamanoSep 7, 2026
  61. Karthik NayakSep 8, 2026
  62. 3/4 receive-pack: move message generation to separate functionKarthik Nayak, Sep 4, 2026
  63. Junio C HamanoSep 7, 2026
  64. Karthik NayakSep 8, 2026
  65. 4/4 hook: introduce the receive-report hookKarthik Nayak, Sep 4, 2026
  66. Junio C HamanoSep 7, 2026
  67. Karthik NayakSep 8, 2026
  68. Patrick SteinhardtSep 7, 2026
  69. Karthik NayakSep 8, 2026
  70. 0/4 hook: introduce the receive-report hookKarthik Nayak, Sep 8, 2026
  71. 1/4 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Sep 8, 2026
  72. 2/4 receive-pack: drop static variables to track report status versionKarthik Nayak, Sep 8, 2026
  73. Junio C HamanoSep 8, 2026
  74. 3/4 receive-pack: move message generation to separate functionKarthik Nayak, Sep 8, 2026
  75. 4/4 hook: introduce the receive-report hookKarthik Nayak, Sep 8, 2026
  76. 0/4 hook: introduce the receive-report hookKarthik Nayak, Sep 9, 2026
  77. 1/4 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Sep 9, 2026
  78. 2/4 receive-pack: drop static variables to track report status versionKarthik Nayak, Sep 9, 2026
  79. 3/4 receive-pack: move message generation to separate functionKarthik Nayak, Sep 9, 2026
  80. 4/4 hook: introduce the receive-report hookKarthik Nayak, Sep 9, 2026
  81. Junio C HamanoSep 10, 2026
  82. Karthik NayakSep 10, 2026
  83. Oswald BuddenhagenSep 11, 2026
  84. Karthik NayakSep 11, 2026
  85. Patrick SteinhardtSep 9, 2026
  86. Junio C HamanoSep 9, 2026
  87. Jeff KingSep 10, 2026
  88. Karthik NayakSep 10, 2026
  89. Karthik NayakSep 10, 2026
  90. 0/4 hook: introduce the receive-report hookKarthik Nayak, Sep 10, 2026
  91. 1/4 doc: add proc-receive hook info in 'git-receive-pack.adoc'Karthik Nayak, Sep 10, 2026
  92. 2/4 receive-pack: drop static variables to track report status versionKarthik Nayak, Sep 10, 2026
  93. 3/4 receive-pack: move message generation to separate functionKarthik Nayak, Sep 10, 2026
  94. 4/4 hook: introduce the receive-report hookKarthik Nayak, Sep 10, 2026
  95. Junio C HamanoSep 11, 2026
  96. Karthik NayakSep 11, 2026
  97. Re* [PATCH v10 4/4] hook: introduce the receive-report hookJunio C Hamano, Sep 14, 2026
  98. Karthik NayakSep 15, 2026

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.