* [PATCH 0/2] Fix shallow clone with ref-in-want enabled
@ 2025-12-24 0:35 Matthew Dodd
2025-12-24 0:35 ` [PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2 Matthew Dodd
2025-12-24 0:35 ` [PATCH 2/2] t5703: add test for shallow fetch with ref-in-want Matthew Dodd
0 siblings, 2 replies; 4+ messages in thread
From: Matthew Dodd @ 2025-12-24 0:35 UTC (permalink / raw)
To: git; +Cc: Brandon Williams, Junio C Hamano, Johannes Schindelin, Mats-Dodd
From: Mats-Dodd <mats.dodd12@gmail•com>
The ref-in-want feature (uploadpack.allowRefInWant) has been broken with
shallow clones since it was introduced in 516e2b76bdc (upload-pack:
implement ref-in-want, 2018-06-27). When enabled, shallow clones fail
with:
fatal: expected 'packfile', received 'shallow-info'
The server sends protocol v2 sections in the wrong order, violating the
specification in Documentation/gitprotocol-v2.adoc and client expectations
in fetch-pack.c.
This series:
1. Fixes the section ordering in upload-pack.c (swap two lines)
2. Adds a regression test for shallow clone + ref-in-want
Mats-Dodd (2):
upload-pack: send shallow-info before wanted-refs in protocol v2
t5703: add test for shallow fetch with ref-in-want
t/t5703-upload-pack-ref-in-want.sh | 9 +++++++++
upload-pack.c | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
base-commit: 9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed
--
2.47.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2
2025-12-24 0:35 [PATCH 0/2] Fix shallow clone with ref-in-want enabled Matthew Dodd
@ 2025-12-24 0:35 ` Matthew Dodd
2026-01-05 13:00 ` Patrick Steinhardt
2025-12-24 0:35 ` [PATCH 2/2] t5703: add test for shallow fetch with ref-in-want Matthew Dodd
1 sibling, 1 reply; 4+ messages in thread
From: Matthew Dodd @ 2025-12-24 0:35 UTC (permalink / raw)
To: git; +Cc: Brandon Williams, Junio C Hamano, Johannes Schindelin, Mats-Dodd
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] t5703: add test for shallow fetch with ref-in-want
2025-12-24 0:35 [PATCH 0/2] Fix shallow clone with ref-in-want enabled Matthew Dodd
2025-12-24 0:35 ` [PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2 Matthew Dodd
@ 2025-12-24 0:35 ` Matthew Dodd
1 sibling, 0 replies; 4+ messages in thread
From: Matthew Dodd @ 2025-12-24 0:35 UTC (permalink / raw)
To: git; +Cc: Brandon Williams, Junio C Hamano, Johannes Schindelin, Mats-Dodd
From: Mats-Dodd <mats.dodd12@gmail•com>
Add a regression test for shallow clone operations when the server has
uploadpack.allowRefInWant enabled. Before the previous commit, this
operation would fail with:
fatal: expected 'packfile', received 'shallow-info'
This was due to the server sending protocol v2 sections in the wrong
order. The test ensures this scenario continues to work.
Signed-off-by: Mats-Dodd <mats.dodd12@gmail•com>
---
t/t5703-upload-pack-ref-in-want.sh | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 249137b467..21f4049eb4 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -256,6 +256,15 @@ test_expect_success 'fetching multiple refs' '
grep "want-ref refs/heads/baz" log
'
+test_expect_success 'fetching with ref-in-want and shallow' '
+ rm -rf local &&
+ git -c protocol.version=2 clone --depth=1 "file://$REPO" local &&
+
+ git -C "$REPO" rev-parse main >expected &&
+ git -C local rev-parse refs/remotes/origin/main >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'fetching ref and exact OID' '
test_when_finished "rm -f log" &&
--
2.47.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2
2025-12-24 0:35 ` [PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2 Matthew Dodd
@ 2026-01-05 13:00 ` Patrick Steinhardt
0 siblings, 0 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2026-01-05 13:00 UTC (permalink / raw)
To: Matthew Dodd; +Cc: git, Brandon Williams, Junio C Hamano, Johannes Schindelin
On Wed, Dec 24, 2025 at 01:35:03AM +0100, Matthew Dodd wrote:
> 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
Nit: is there a word missing here? E.g. "Fix this by..."
> 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);
Indeed. The accompanying code in "fetch-pack.c" expects information the
other way round:
if (process_section_header(&reader, "shallow-info", 1))
receive_shallow_info(args, &reader, shallows, si);
if (process_section_header(&reader, "wanted-refs", 1))
receive_wanted_refs(&reader, sought, nr_sought);
The bug seems to exist since the inception of this feature. 516e2b76bd
(upload-pack: implement ref-in-want, 2018-06-27) implements the server
side in the current-broken way, and 733020517a (fetch-pack: implement
ref-in-want, 2018-06-27) implements the client side in the correct way.
So this combination has always been broken, and the fix looks obviously
correct to me indeed.
One nit though: I don't really think it's necessary to split up this
series into two patches. The new test can simply be added to this commit
here.
Thanks!
Patrick
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-05 13:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-24 0:35 [PATCH 0/2] Fix shallow clone with ref-in-want enabled Matthew Dodd
2025-12-24 0:35 ` [PATCH 1/2] upload-pack: send shallow-info before wanted-refs in protocol v2 Matthew Dodd
2026-01-05 13:00 ` Patrick Steinhardt
2025-12-24 0:35 ` [PATCH 2/2] t5703: add test for shallow fetch with ref-in-want Matthew Dodd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox