From 66d34c7d08d7c536c3165dc49ed318e73ea5acc2 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 17 Jan 2024 15:00:40 -0500 Subject: [PATCH] cmd/go/internal/modfetch: set protocol.version=2 for shallow git fetches This works around an apparent bug in the Git HTTP backend, introduced in Git 2.21, that causes responses for the version 1 protocol to provide incomplete tags. For Git commands older than 2.18, this configuration flag is ignored. (Note that Git 2.29 and above already use protocol version 2 by default.) Fixes #56881. Change-Id: I9b241cfb604e5f633ca6a5d799df6706246684a7 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/556358 Run-TryBot: Bryan Mills LUCI-TryBot-Result: Go LUCI TryBot-Result: Gopher Robot Reviewed-by: Michael Matloob --- src/cmd/go/internal/modfetch/codehost/git.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go index d3a713223c..7d9e5d82f9 100644 --- a/src/cmd/go/internal/modfetch/codehost/git.go +++ b/src/cmd/go/internal/modfetch/codehost/git.go @@ -550,7 +550,11 @@ func (r *gitRepo) stat(ctx context.Context, rev string) (info *RevInfo, err erro if err != nil { return nil, err } - _, err = Run(ctx, r.dir, "git", "fetch", "-f", "--depth=1", r.remote, refspec) + // We explicitly set protocol.version=2 for this command to work around + // an apparent Git bug introduced in Git 2.21 (commit 61c771), + // which causes the handler for protocol version 1 to sometimes miss + // tags that point to the requested commit (see https://go.dev/issue/56881). + _, err = Run(ctx, r.dir, "git", "fetch", "-f", "-c", "protocol.version=2", "--depth=1", r.remote, refspec) release() if err == nil { -- 2.48.1