[PATCH v8 0/4] hook: introduce the receive-report hook
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Sep 8, 2026, 10:27 UTC
- Message-ID
- <20260908-758-introduce-hook-v8-0-be88a671ae1f@gmail.com>
- In-Reply-To
- <20260818-758-introduce-hook-v1-1-8a8d89e65838@gmail.com>
Introduce a new receive-report hook which kicks in after the reference transaction is complete, but before the report is sent to the client. The hook receives the pkt-line encoded report in its stdin and its stdout replaces the report transferred to the user. If the hook exits with a non-zero exit code, all references are marked as rejected.
The first patch, adds missing documentation to 'git-receive-pack.adoc'. The second patch refactors code and the third patch contains the new hook.
--- Changes in v8: - Fix spelling mistake s/UNKOWN/UNKNOWN - Remove a stale comment from previous version. - Fix an argument which wasn't changed with the previous version's changes. - Link to v7: https://patch.msgid.link/20260904-758-introduce-hook-v7-0-6c66f0a3a572@gmail.com
Changes in v7: - Removed report_v2() since it is the same as report() with the new changes. - Used a switch statement instead of an if/else for the enum. - Removed an unnecessary curly brace. - Also rebased on top of latest master (3cb9185f65 (The 22nd batch, 2026-09-02) as there were conflicts. - Link to v6: https://patch.msgid.link/20260903-758-introduce-hook-v6-0-6283b1fb9b1c@gmail.com
Changes in v6:
- Introduce a new commit which introduces `enum report_status_version`,
use that and drop static variables in the codebase.
- Reword the commit message and documentation to:
- State further why reference-transaction cannot be used.
- State the responsibility of the hook owner to undo and reference
changes if needed.
- Link to v5: https://patch.msgid.link/20260901-758-introduce-hook-v5-0-35cdc6be3cc1@gmail.comChanges in v5:
- Rewrote some of the commit messages and documentation.
- Renamed the function `generate_response` to `generate_report` to avoid
ambiguity.
- We now override the cmd's error_strings, this avoids the whole
precedence issue with the earlier series.
- Also add information about how we can override the unpack status to
fail the push and add a corresponding test.
- Thanks to Patrick for the review!
- Junio: This causes conflict with next ('jt/receive-pack-pluggable-writes')
similar to before, please let me know if its better for me to add that
dependency.
- Link to v4: https://patch.msgid.link/20260826-758-introduce-hook-v4-0-6b14975ad957@gmail.comChanges in v4: - Change the name of the hook to be 'receive-report' to avoid ambiguity. - Link to v3: https://patch.msgid.link/20260824-758-introduce-hook-v3-0-499526f0a062@gmail.com
Changes in v3: - Move out addition of proc-receive hook doc to 'git-receive-pack.adoc' into a new commit. - Add a new commit to move out the response generation in receive-pack to a new function. - Instead of die-ing on non-zero exit code, we modify each reference to indicate that the hook failed. - Instead of correctly listing out the protocol, link to linkgit:gitprotocol-pack[5], as the protocol also differs between v1 and v2. - Link to v2: https://patch.msgid.link/20260821-758-introduce-hook-v2-1-e90e2f7ac2cf@gmail.com
Changes in v2: - Modify the documentation and commit message to be more verbose. - Add documentation to 'git-receive-pack.adoc' - Use 'ret' as the variable name for the return code. - Modify the test to also check for the 'remote:'. - Link to v1: https://patch.msgid.link/20260818-758-introduce-hook-v1-1-8a8d89e65838@gmail.com
To: git@vger.kernel.org CC: ps@pks.im CC: gitster@pobox.com CC: jltobler@gmail.com CC: kristofferhaugsbakk@fastmail.com CC: phillip.wood123@gmail.com
---
Karthik Nayak (4):
doc: add proc-receive hook info in 'git-receive-pack.adoc'
receive-pack: drop static variables to track report status version
receive-pack: move message generation to separate function
hook: introduce the receive-report hookDocumentation/git-receive-pack.adoc | 17 +++ Documentation/githooks.adoc | 61 ++++++++++ builtin/receive-pack.c | 146 +++++++++++++++-------- t/meson.build | 1 + t/t5412-receive-report-hook.sh | 224 ++++++++++++++++++++++++++++++++++++ 5 files changed, 401 insertions(+), 48 deletions(-)
Range-diff versus v7:
1: a80b77f284 = 1: 55f08ef482 doc: add proc-receive hook info in 'git-receive-pack.adoc'
2: 116699bd30 ! 2: df5840c4fa receive-pack: drop static variables to track report status version
@@ builtin/receive-pack.c: enum deny_action {
};
+enum report_status_version {
-+ REPORT_STATUS_UNKOWN = 0,
++ REPORT_STATUS_UNKNOWN = 0,
+ REPORT_STATUS_V0,
+ REPORT_STATUS_V2,
+};
@@ builtin/receive-pack.c: int cmd_receive_pack(int argc,
struct shallow_info si;
struct packet_reader reader;
struct odb_transaction *transaction = NULL;
-+ enum report_status_version version = REPORT_STATUS_UNKOWN;
++ enum report_status_version version = REPORT_STATUS_UNKNOWN;
struct option options[] = {
OPT__QUIET(&quiet, N_("quiet")),
3: e36b4e7a21 ! 3: d7c3b7ed55 receive-pack: move message generation to separate function
@@ builtin/receive-pack.c: static void update_shallow_info(struct command *commands
-static void report(struct command *commands, const struct strbuf *unpack_status)
+/*
+ * Generate the response to be sent to the client invoking 'git-receive-pack(1)'.
-+ * For v2 protocol, set `detailed_report` to true, which will also add detailed
-+ * report per reference update.
+ */
+static void generate_report(struct strbuf *buf, struct command *commands,
+ const struct strbuf *unpack_status,
4: e7c1c0d196 ! 4: d0e632235a hook: introduce the receive-report hook
@@ builtin/receive-pack.c: 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 `detailed_report` to true, which will also add detailed
+ */
@@ builtin/receive-pack.c: static void report(struct command *commands, const struct strbuf *unpack_status,
generate_report(&buf, commands, unpack_status, version);
@@ builtin/receive-pack.c: static void report(struct command *commands, const struc
+ if (run_receive_report_hook(&buf)) {
+ strbuf_reset(&buf);
+ override_cmds_error(commands, "receive-report hook failed");
-+ generate_report(&buf, commands, unpack_status, false);
++ generate_report(&buf, commands, unpack_status, version);
+ }
+
if (use_sideband)--- base-commit: 3cb9185f65410273787f74333cc027d2ea5daada change-id: 20260812-758-introduce-hook-5b3af9f1a7e8
Thanks - Karthik