From abe49196b80e367f7cc123a095b32958f8d0470b Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Sat, 1 Jul 2023 15:37:24 +0100 Subject: plumbing: http, Fix empty repos on Git v2.41+ Git v2.41.0 comes with [changes](https://github.com/git/git/commit/933e3a4ee205353d8f093d5dfcd226fa432c4e58) that breaks go-git's assumptions for when detecting empty repositories. Go-git expects a flush instead of the first hash line. Instead, a dummy capabilities^{} with zero-id is returned. The change aims to allow for identifying the object format even when cloning empty repositories. Signed-off-by: Paulo Gomes --- plumbing/transport/http/common.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'plumbing/transport/http') diff --git a/plumbing/transport/http/common.go b/plumbing/transport/http/common.go index f9b7a0e..a7cdc1e 100644 --- a/plumbing/transport/http/common.go +++ b/plumbing/transport/http/common.go @@ -73,6 +73,17 @@ func advertisedReferences(ctx context.Context, s *session, serviceName string) ( return nil, err } + // Git 2.41+ returns a zero-id plus capabilities when an empty + // repository is being cloned. This skips the existing logic within + // advrefs_decode.decodeFirstHash, which expects a flush-pkt instead. + // + // This logic aligns with plumbing/transport/internal/common/common.go. + if ar.IsEmpty() && + // Empty repositories are valid for git-receive-pack. + transport.ReceivePackServiceName != serviceName { + return nil, transport.ErrEmptyRemoteRepository + } + transport.FilterUnsupportedCapabilities(ar.Capabilities) s.advRefs = ar -- cgit