From: Dominik Maier <dmnk@google.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Ivan Frade <ifrade@google.com>,
Xing Xin <xingxin.xx@bytedance.com>,
dmnk+artist@google.com, Dominik Maier <dmnk@google.com>
Subject: [PATCH] connect: clear v2 server capabilities on handshake
Date: Thu, 19 Nov 2026 20:22:57 +0100 [thread overview]
Message-ID: <20261119192257.2679418-1-dmnk@google.com> (raw)
process_capabilities_v2() appends capability lines onto the file-static
server_capabilities_v2 vector without clearing entries recorded during
earlier handshakes in the same process. Because server_feature_v2() and
server_supports_feature() return the first matching entry in
server_capabilities_v2, capabilities advertised by an earlier remote
bleed into subsequent connections (including v0/v1 handshakes that skip
process_capabilities_v2() before callers such as get_bundle_uri() query
server_supports_v2("bundle-uri")).
For example, running "git remote show r1 r2" when r1 uses SHA-256 and r2
uses SHA-1 causes the second handshake to read r1's stale
"object-format=sha256" capability and fail with "mismatched object
format", and a stale "session-id" from r1 is logged again for r2 even
when r2 disables transfer.advertiseSID.
Clear server_capabilities_v2 in discover_version() and
process_capabilities_v2().
Signed-off-by: Dominik Maier <dmnk@google.com>
---
connect.c | 3 +++
t/t5702-protocol-v2.sh | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/connect.c b/connect.c
index 87d2e8bccd..b620cf2286 100644
--- a/connect.c
+++ b/connect.c
@@ -133,6 +133,7 @@ int server_supports_feature(const char *c, const char *feature,
static void process_capabilities_v2(struct packet_reader *reader)
{
+ strvec_clear(&server_capabilities_v2);
while (packet_reader_read(reader) == PACKET_READ_NORMAL)
strvec_push(&server_capabilities_v2, reader->line);
@@ -144,6 +145,8 @@ enum protocol_version discover_version(struct packet_reader *reader)
{
enum protocol_version version = protocol_unknown_version;
+ strvec_clear(&server_capabilities_v2);
+
/*
* Peek the first line of the server's response to
* determine the protocol version the server is speaking.
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index e5e73eb407..3716e43bb1 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -548,6 +548,29 @@ test_expect_success 'invalid server-option configuration' '
test_grep "error: missing value for '\''remote.origin.serveroption'\''" err
'
+test_expect_success 'v2 server capabilities do not bleed across in-process handshakes' '
+ test_when_finished "rm -rf cap_r1 cap_r2 cap_client trace2_caps" &&
+ git init --object-format=sha256 cap_r1 &&
+ test_commit -C cap_r1 one &&
+ git -C cap_r1 config transfer.advertiseSID true &&
+
+ git init --object-format=sha1 cap_r2 &&
+ test_commit -C cap_r2 two &&
+ git -C cap_r2 config transfer.advertiseSID false &&
+
+ git init --object-format=sha1 cap_client &&
+ git -C cap_client remote add r1 "file://$(pwd)/cap_r1" &&
+ git -C cap_client remote add r2 "file://$(pwd)/cap_r2" &&
+
+ GIT_TRACE2_EVENT="$(pwd)/trace2_caps" \
+ git -C cap_client -c protocol.version=2 -c transfer.advertiseSID=true \
+ remote show r1 r2 >out &&
+ test_grep "\* remote r2" out &&
+ grep "\"category\":\"transfer\",\"key\":\"server-sid\"" trace2_caps >sids &&
+ # Only r1 advertised session-id; r2 must not inherit it
+ test_line_count = 1 sids
+'
+
test_expect_success 'upload-pack respects config using protocol v2' '
git init server &&
write_script server/.git/hook <<-\EOF &&
--
2.56.1.750.gf70dc682cf-goog
reply other threads:[~2026-11-19 19:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261119192257.2679418-1-dmnk@google.com \
--to=dmnk@google.com \
--cc=dmnk+artist@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ifrade@google.com \
--cc=ps@pks.im \
--cc=xingxin.xx@bytedance.com \
/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