From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, ps@pks.im, jltobler@gmail.com,
kristofferhaugsbakk@fastmail.com,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH v5 3/3] hook: introduce the receive-report hook
Date: Tue, 01 Sep 2026 10:03:26 -0700 [thread overview]
Message-ID: <xmqq4ig8uco1.fsf@gitster.g> (raw)
In-Reply-To: <20260901-758-introduce-hook-v5-3-35cdc6be3cc1@gmail.com> (Karthik Nayak's message of "Tue, 01 Sep 2026 17:19:25 +0200")
Karthik Nayak <karthik.188@gmail.com> writes:
> We cannot use any of the existing hooks as:
>
> - The pre-receive hook runs too early, as we haven't updated
> references at that point yet and we need to have the full view of
> all resulting updates (both objects and references).
>
> - The update hook is too inefficient as it runs once per reference,
> and we cannot trivially determine the last update.
>
> - The reference-transaction hook cannot be used by us because we care
> about the phase where it was committed already. And while the hook
> fires in that phase, it does not allow the caller to modify the
> result in any capacity.
Here you explain that the reason this is not suited for your use
case is because it does not allow the caller to modify the result.
The transaction hook is notified in what phase of the reference
updates we are in, and what updates are planned or have happened.
But the hook cannot interfere to change the outcome (except it can
make the transaction abort as a whole in preparation phases).
> - The post-receive and post-update hooks cannot be used as they run
> too late, at the point where we have already reported success to the
> client.
>
> Introduce a new 'receive-report' hook. The hook receives the complete
> pkt-line encoded status report on standard input, after all ref updates
> have been applied to the repository by execute_commands() but before the
> report is sent to the client. See linkgit:gitprotocol-pack[5] details on
> the protocol structure.
>
> The hook's stdout fully replaces the report sent to the client.
> receive-pack fully buffers the hook's stdout before acting on the exit
> status, so the exit code is known before the client receives anything.
> This gives two distinct behaviors depending on exit status:
>
> - Exit 0: the hook's stdout is used as the report. The hook can
> rewrite 'ok' lines to 'ng' lines to signal per-ref rejection to the
> client while receive-pack itself exits cleanly. The client marks
> rejected refs as '[remote rejected]' and exits with a non-zero
> status if any ref is 'ng'.
>
> - Non-zero exit: the hook's stdout is discarded, receive-pack modifies
> all references to be rejected with a 'receive-report hook failed'
> error.
And the new hook lets you pretend to the other side of the
connection that ref updates that happened on our side is totally
different from what actually happened, but ...
> In both cases, any output the hook writes to standard error is
> forwarded to the client over the sideband channel and appears as
> 'remote:' lines on the client terminal. Writing to stderr alone does
> not affect the push outcome.
>
> Note that in either failure mode, ref updates already applied by
> execute_commands() are not rolled back. The hook can cause the client
> to perceive the push as failed, but cannot undo server-side changes.
... it still cannot interfere to change the outcome. What has been
committed as reference updates have happened and there is no way to
change it. So the reason to reject reference-transaction hook seems
a bit weak. The explanation I heard so far makes it sound as if it
is an equally viable, if not even more viable, alternative to teach
the reference-transaction hook at the commit phase to optionally
allow rejecting the transaction, instead of adding an entirely
different hook (note: I am not suggesting it as an alternative; I am
just saying that the explanation is weak to support this design).
In any case, if the actual ref updates and the reported ref updates
result can be made different, somebody then needs to step in and
reconcile the inconsistencies, no?
The way pusher perceives the state of their remote repository they
just pushed to, which they learn from the output of receive-report
hook, would have no link to reality when this hook is used on the
remote side. This may matter because the "git push" updates its own
remote-tracking branches to match what the remote says (i.e.,
pretends as if "git push" was immediately followed by "git fetch" to
the same remote).
next prev parent reply other threads:[~2026-09-01 17:03 UTC|newest]
Thread overview: 44+ 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
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 [this message]
2026-09-02 14:42 ` 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=xmqq4ig8uco1.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=karthik.188@gmail.com \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.