[PATCH] connect: clear v2 server capabilities on handshake
- From
- Dominik Maier <dmnk@google.com>
- Date
- Nov 19, 2026, 19:22 UTC
- Message-ID
- <20261119192257.2679418-1-dmnk@google.com>
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