Git development
 help / color / mirror / Atom feed
From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, gitster@pobox.com, jltobler@gmail.com,
	 kristofferhaugsbakk@fastmail.com,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	 Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v10 0/4] hook: introduce the receive-report hook
Date: Thu, 10 Sep 2026 23:54:05 +0200	[thread overview]
Message-ID: <20260910-758-introduce-hook-v10-0-06f9c506631c@gmail.com> (raw)
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 v10:
- Fix a leak when reassigning the command strings.
- Link to v9: https://patch.msgid.link/20260909-758-introduce-hook-v9-0-3043d417e0ee@gmail.com

Changes in v9:
- Fix a bug where we were causing a BUG() when no report was requested.
  It is perfectly valid for clients to skip the report and we shouldn't
  fail when they do so. Thanks Junio!
- Link to v8: https://patch.msgid.link/20260908-758-introduce-hook-v8-0-be88a671ae1f@gmail.com

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.com

Changes 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.com

Changes 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 hook

 Documentation/git-receive-pack.adoc |  17 +++
 Documentation/githooks.adoc         |  61 +++++++++
 builtin/receive-pack.c              | 147 ++++++++++++++-------
 t/meson.build                       |   1 +
 t/t5412-receive-report-hook.sh      | 257 ++++++++++++++++++++++++++++++++++++
 5 files changed, 436 insertions(+), 47 deletions(-)

Range-diff versus v9:

1:  711a817307 = 1:  c1e4b04739 doc: add proc-receive hook info in 'git-receive-pack.adoc'
2:  9e2df905d2 = 2:  a722caf2ab receive-pack: drop static variables to track report status version
3:  b871b95544 = 3:  beff68683c receive-pack: move message generation to separate function
4:  3d4e967fa5 ! 4:  8819db1ae1 hook: introduce the receive-report hook
    @@ builtin/receive-pack.c: static void update_shallow_info(struct command *commands
      
     +static void override_cmds_error(struct command *commands, const char *err)
     +{
    -+	for (struct command *cmd = commands; cmd; cmd = cmd->next)
    ++	for (struct command *cmd = commands; cmd; cmd = cmd->next) {
    ++		if (cmd->error_string_owned)
    ++			FREE_AND_NULL(cmd->error_string_owned);
     +		cmd->error_string = err;
    ++	}
     +}
     +
      /*
    @@ t/t5412-receive-report-hook.sh (new)
     +	test_cmp expect-report actual-report
     +'
     +
    ++test_expect_success "non-zero exit with pre-existing ng from proc-receive" '
    ++	test_when_finished "rm -rf upstream" &&
    ++	test_when_finished "git -C workbench remote remove origin" &&
    ++
    ++	git init --bare upstream &&
    ++	git -C upstream config receive.procReceiveRefs refs/for &&
    ++	git -C workbench remote add origin ../upstream &&
    ++	git -C workbench push origin $A:refs/heads/main &&
    ++
    ++	# Use a proc-receive hook to generate a dynamic error string.
    ++	# This is used to capture any leaks stemming from overriding the
    ++	# error message via the receive-report.
    ++	test_hook -C upstream --setup proc-receive <<-\EOF &&
    ++	test-tool proc-receive -r "ng refs/for/main/topic push-rejected-by-service-x"
    ++	EOF
    ++
    ++	test_hook -C upstream --setup receive-report <<-\EOF &&
    ++	tee raw
    ++	exit 1
    ++	EOF
    ++
    ++	test_must_fail git -C workbench push origin HEAD:refs/for/main/topic >out 2>&1 &&
    ++	test_grep "receive-report hook failed" out &&
    ++
    ++	test-tool pkt-line unpack <upstream/raw >actual-report &&
    ++	cat >expect-report <<-\EOF &&
    ++	unpack ok
    ++	ng refs/for/main/topic push-rejected-by-service-x
    ++	0000
    ++	EOF
    ++	test_cmp expect-report actual-report
    ++'
    ++
     +test_expect_success "hook stderr is relayed to client via sideband" '
     +	test_when_finished "rm -rf upstream" &&
     +	test_when_finished "git -C workbench remote remove origin" &&

---
base-commit: 3cb9185f65410273787f74333cc027d2ea5daada
change-id: 20260812-758-introduce-hook-5b3af9f1a7e8


Thanks
- Karthik


  parent reply	other threads:[~2026-09-11 21:21 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
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 ` Karthik Nayak [this message]
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=20260910-758-introduce-hook-v10-0-06f9c506631c@gmail.com \
    --to=karthik.188@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox