git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2

From
MDMatthew Dodd <mats.dodd12@gmail.com>
Date
Dec 24, 2025, 00:35 UTC
Message-ID
<20251224003504.52660-2-mats.dodd12@gmail.com>
In-Reply-To
<20251224003504.52660-1-mats.dodd12@gmail.com>
From: Mats-Dodd <mats.dodd12@gmail.com>

The protocol v2 specification (Documentation/gitprotocol-v2.adoc) defines the ordering of optional sections in the fetch response as:

    [acknowledgments delim-pkt] [shallow-info delim-pkt]
    [wanted-refs delim-pkt] [packfile-uris delim-pkt]
    packfile flush-pkt

However, since the ref-in-want feature was introduced in 516e2b76bdc (upload-pack: implement ref-in-want, 2018-06-27), the server sends wanted-refs before shallow-info. This violates the specification and breaks the client (fetch-pack.c), which expects shallow-info first.

When a client performs a shallow clone/fetch against a server with uploadpack.allowRefInWant=true, the client receives sections in the wrong order and fails with:

    fatal: expected 'packfile', received 'shallow-info'

Fix by swapping the order of send_shallow_info() and send_wanted_ref_info() to match both the protocol specification and client expectations.

Signed-off-by: Mats-Dodd <mats.dodd12@gmail.com>
---
 upload-pack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/upload-pack.c b/upload-pack.c
index 1e87ae9559..029ca93e69 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1830,8 +1830,8 @@ int upload_pack_v2(struct repository *r, struct packet_reader *request)
 				state = UPLOAD_DONE;
 			break;
 		case UPLOAD_SEND_PACK:
-			send_wanted_ref_info(&data);
 			send_shallow_info(&data);
+			send_wanted_ref_info(&data);
 
 			if (data.uri_protocols.nr) {
 				create_pack_file(&data, &data.uri_protocols);
-- 
2.47.0
Previous: Matthew DoddNext: Patrick Steinhardt
Message 2 of 4 in “Fix shallow clone with ref-in-want enabled”
  1. 0/2 Fix shallow clone with ref-in-want enabledMatthew Dodd, Dec 24, 2025
  2. 1/2 upload-pack: send shallow-info before wanted-refs in protocol v2Matthew Dodd, Dec 24, 2025
  3. Patrick SteinhardtJan 5, 2026
  4. 2/2 t5703: add test for shallow fetch with ref-in-wantMatthew Dodd, Dec 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.