From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com,
kristofferhaugsbakk@fastmail.com,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH v4 3/3] hook: introduce the receive-report hook
Date: Mon, 31 Aug 2026 08:45:04 +0200 [thread overview]
Message-ID: <apUi8I-b69XxDAYY@pks.im> (raw)
In-Reply-To: <20260826-758-introduce-hook-v4-3-6b14975ad957@gmail.com>
On Wed, Aug 26, 2026 at 12:19:39PM +0200, Karthik Nayak wrote:
> diff --git a/Documentation/git-receive-pack.adoc b/Documentation/git-receive-pack.adoc
> index 4349487e6a..f2d52b7df2 100644
> --- a/Documentation/git-receive-pack.adoc
> +++ b/Documentation/git-receive-pack.adoc
> @@ -243,6 +243,15 @@ requests. It handles refs whose names match the patterns defined by
> `receive.procReceiveRefs` and executes the actual ref updates. See
> linkgit:githooks[5] for the full protocol description.
>
> +RECEIVE-REPORT HOOK
> +-------------------
> +This hook is invoked by 'git-receive-pack' after all the ref updates
> +have been applied but before the report is sent to the client. The hook
> +receives the complete report in pkt-line format on stdin and its stdout
> +replaces the report sent to the client. Allowing the hook to rewrite
s/\. Allowing/, which allows/
> diff --git a/Documentation/githooks.adoc b/Documentation/githooks.adoc
> index ed045940d1..e83ebde667 100644
> --- a/Documentation/githooks.adoc
> +++ b/Documentation/githooks.adoc
> @@ -527,6 +527,49 @@ 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.
>
> +receive-report
> +~~~~~~~~~~~~~~
> +
> +This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
> +`git push` and updates references in its repository. It executes on
> +the repository once after all refs have been updated and after all
> +accepted ref changes are applied to the repository, but before the
> +pkt-line encoded status report is sent back to the client.
> +
> +The hook receives the complete pkt-line encoded status report on
> +standard input, see linkgit:gitprotocol-pack[5] for details on the
> +structure. The hook's standard output entirely replaces the report
> +that is sent to the client. The hook must write a valid pkt-line
> +encoded report in the same format it received. The hook's stdout is
> +fully buffered by `receive-pack` before any data is sent to the client,
> +so the hook's exit status is known before the client receives anything.
> +
> +There are two distinct ways the hook can affect the push outcome:
Aren't there three? The hook can also update the "unpack" status to
indicate failure.
> +* To reject individual ref updates while keeping `receive-pack` alive,
> + rewrite the corresponding `ok <refname>` lines to
> + `ng <refname> <reason>` lines in the output and exit with status 0.
s/ <reason>/[ <reason>]/
> + The client will then mark those specific refs as rejected while
> + treating any `ok` refs as successful. The push as a whole is
> + considered failed if any ref is `ng`, and `git push` will exit with
> + a non-zero status on the client side.
> +
> +* To abort the entire push unconditionally, exit with a non-zero
> + status. In this case the hook's stdout is discarded, `receive-pack`
> + modifies all references to be rejected with a 'receive-report hook
Yup, I think this is a lot more sensible.
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index 70a686c142..1358285589 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -2534,9 +2569,12 @@ static void update_shallow_info(struct command *commands,
> * Generate the response to be sent to the client invoking 'git-receive-pack(1)'.
> * For v2 protocol, set `add_reports` to true, which will also add additional
> * report per reference update.
> + * If `ref_error` is set, then all references will be rejected with the given
> + * error message.
> */
> static void generate_response(struct strbuf *buf, struct command *commands,
> - const char *unpack_status, bool add_reports)
> + const char *unpack_status, bool add_reports,
> + const char *ref_error)
> {
> struct command *cmd;
>
> @@ -2550,10 +2588,13 @@ static void generate_response(struct strbuf *buf, struct command *commands,
> if (cmd->error_string)
> packet_buf_write(buf, "ng %s %s\n",
> cmd->ref_name, cmd->error_string);
> + else if (ref_error)
> + packet_buf_write(buf, "ng %s %s\n",
> + cmd->ref_name, ref_error);
Precedence is a bit weird here, as I would have expected the explicit
error to override the implicit per-command ones. It also raises the
question whether it's correct to retain any populated error strings in
favor of updating everything to "receive-report hook failed".
This makes me wonder whetther it would be preferable to update the
`cmd->error_string`s instead of adding this new parameter?
Thanks!
Patrick
next prev parent reply other threads:[~2026-08-31 6:45 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 7:55 [PATCH] hook: introduce the report hook for git-receive-pack(1) Karthik Nayak
2026-08-18 20:54 ` Junio C Hamano
2026-08-19 7:03 ` Kristoffer Haugsbakk
2026-08-19 12:11 ` Karthik Nayak
2026-08-19 14:47 ` Kristoffer Haugsbakk
2026-08-19 7:39 ` Patrick Steinhardt
2026-08-19 13:13 ` Karthik Nayak
2026-08-19 13:20 ` Patrick Steinhardt
2026-08-19 13:24 ` Karthik Nayak
2026-08-20 9:50 ` Phillip Wood
2026-08-20 15:43 ` Junio C Hamano
2026-08-21 12:51 ` Karthik Nayak
2026-08-21 13:34 ` [PATCH v2] " Karthik Nayak
2026-08-21 13:49 ` Patrick Steinhardt
2026-08-21 16:08 ` Karthik Nayak
2026-08-24 5:32 ` Patrick Steinhardt
2026-08-24 8:14 ` Karthik Nayak
2026-08-21 16:55 ` Junio C Hamano
2026-08-24 10:20 ` [PATCH v3 0/3] " Karthik Nayak
2026-08-24 10:20 ` [PATCH v3 1/3] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-08-24 10:21 ` [PATCH v3 2/3] receive-pack: move message generation to separate function Karthik Nayak
2026-08-24 10:21 ` [PATCH v3 3/3] hook: introduce the report hook for git-receive-pack(1) Karthik Nayak
2026-08-24 15:35 ` [PATCH v3 0/3] " Junio C Hamano
2026-08-24 15:57 ` Junio C Hamano
2026-08-24 17:00 ` Patrick Steinhardt
2026-08-26 8:35 ` Karthik Nayak
2026-08-26 14:39 ` Junio C Hamano
2026-08-26 10:19 ` [PATCH v4 0/3] hook: introduce the receive-report hook Karthik Nayak
2026-08-26 10:19 ` [PATCH v4 1/3] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-08-31 6:44 ` Patrick Steinhardt
2026-08-31 18:22 ` Karthik Nayak
2026-08-26 10:19 ` [PATCH v4 2/3] receive-pack: move message generation to separate function Karthik Nayak
2026-08-31 6:44 ` Patrick Steinhardt
2026-08-31 19:05 ` Karthik Nayak
2026-08-26 10:19 ` [PATCH v4 3/3] hook: introduce the receive-report hook Karthik Nayak
2026-08-31 6:45 ` Patrick Steinhardt [this message]
2026-09-01 15:19 ` [PATCH v5 0/3] " Karthik Nayak
2026-09-01 15:19 ` [PATCH v5 1/3] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-01 15:19 ` [PATCH v5 2/3] receive-pack: move message generation to separate function Karthik Nayak
2026-09-01 16:23 ` Junio C Hamano
2026-09-02 11:23 ` Karthik Nayak
2026-09-01 15:19 ` [PATCH v5 3/3] hook: introduce the receive-report hook Karthik Nayak
2026-09-01 17:03 ` Junio C Hamano
2026-09-02 14:42 ` Karthik Nayak
2026-09-02 19:14 ` Junio C Hamano
2026-09-03 9:27 ` [PATCH v6 0/4] " Karthik Nayak
2026-09-03 9:27 ` [PATCH v6 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-03 9:27 ` [PATCH v6 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-03 10:03 ` Patrick Steinhardt
2026-09-03 16:31 ` Karthik Nayak
2026-09-03 9:28 ` [PATCH v6 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-03 10:03 ` Patrick Steinhardt
2026-09-03 16:32 ` Karthik Nayak
2026-09-03 9:28 ` [PATCH v6 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-03 10:03 ` Patrick Steinhardt
2026-09-03 16:32 ` Karthik Nayak
2026-09-04 21:28 ` [PATCH v7 0/4] " Karthik Nayak
2026-09-04 21:28 ` [PATCH v7 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-04 21:28 ` [PATCH v7 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-07 20:58 ` Junio C Hamano
2026-09-08 9:22 ` Karthik Nayak
2026-09-04 21:28 ` [PATCH v7 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-07 20:58 ` Junio C Hamano
2026-09-08 9:22 ` Karthik Nayak
2026-09-04 21:28 ` [PATCH v7 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-07 20:58 ` Junio C Hamano
2026-09-08 9:57 ` Karthik Nayak
2026-09-07 6:06 ` [PATCH v7 0/4] " Patrick Steinhardt
2026-09-08 11:48 ` Karthik Nayak
2026-09-08 10:27 ` [PATCH v8 " Karthik Nayak
2026-09-08 10:27 ` [PATCH v8 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-08 10:27 ` [PATCH v8 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-08 19:50 ` Junio C Hamano
2026-09-08 10:27 ` [PATCH v8 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-08 10:27 ` [PATCH v8 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-09 14:51 ` [PATCH v9 0/4] " Karthik Nayak
2026-09-09 14:51 ` [PATCH v9 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-09 14:51 ` [PATCH v9 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-09 14:51 ` [PATCH v9 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-09 14:51 ` [PATCH v9 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-10 3:15 ` Junio C Hamano
2026-09-10 16:32 ` Karthik Nayak
2026-09-11 13:54 ` Oswald Buddenhagen
2026-09-11 21:23 ` Karthik Nayak
2026-09-09 15:00 ` [PATCH v9 0/4] " Patrick Steinhardt
2026-09-09 17:20 ` Junio C Hamano
2026-09-10 4:02 ` Jeff King
2026-09-10 16:40 ` Karthik Nayak
2026-09-10 13:43 ` Karthik Nayak
2026-09-10 21:54 ` [PATCH v10 " Karthik Nayak
2026-09-10 21:54 ` [PATCH v10 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-10 21:54 ` [PATCH v10 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-10 21:54 ` [PATCH v10 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-10 21:54 ` [PATCH v10 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-11 21:39 ` Junio C Hamano
2026-09-11 21:58 ` Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=apUi8I-b69XxDAYY@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jltobler@gmail.com \
--cc=karthik.188@gmail.com \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox