From: Quan Tong Date: Fri, 7 Feb 2025 11:42:26 +0000 (+0700) Subject: [release-branch.go1.24] cmd/go: initialize req.Header when loading git credential X-Git-Tag: go1.24.1~21 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=80e2e474b8d9124d03b744f4e2da099a4eec5957;p=gostls13.git [release-branch.go1.24] cmd/go: initialize req.Header when loading git credential Fixes #71687 Change-Id: I3d733a50b4451dfb571aba91a28387ba9e0614dc Reviewed-on: https://go-review.googlesource.com/c/go/+/647615 Reviewed-by: Michael Matloob Reviewed-by: Sam Thanawalla LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov (cherry picked from commit 58834c3ee08ea85b764c7cc3318ce7a68ea92cbd) Reviewed-on: https://go-review.googlesource.com/c/go/+/648936 Reviewed-by: Dmitri Shuralyov TryBot-Bypass: Dmitri Shuralyov Auto-Submit: Dmitri Shuralyov --- diff --git a/src/cmd/go/internal/auth/auth.go b/src/cmd/go/internal/auth/auth.go index 79e0d8b5e8..83c28d160c 100644 --- a/src/cmd/go/internal/auth/auth.go +++ b/src/cmd/go/internal/auth/auth.go @@ -128,7 +128,8 @@ func runGoAuth(client *http.Client, res *http.Response, url string) { // If no GOAUTH command provided a credential for the given url // and an error occurred, log the error. if cfg.BuildX && url != "" { - if ok := loadCredential(&http.Request{}, url); !ok && len(cmdErrs) > 0 { + req := &http.Request{Header: make(http.Header)} + if ok := loadCredential(req, url); !ok && len(cmdErrs) > 0 { log.Printf("GOAUTH encountered errors for %s:", url) for _, err := range cmdErrs { log.Printf(" %v", err) diff --git a/src/cmd/go/testdata/script/goauth_git.txt b/src/cmd/go/testdata/script/goauth_git.txt index 4fae39aaa7..37c9b19a04 100644 --- a/src/cmd/go/testdata/script/goauth_git.txt +++ b/src/cmd/go/testdata/script/goauth_git.txt @@ -49,6 +49,8 @@ go get vcs-test.golang.org/auth/or401 go mod tidy go list all stdout vcs-test.golang.org/auth/or404 +# With cached credentials, re-downloading in debug mode should succeed. +go get -x vcs-test.golang.org/auth/or401 # Clearing GOAUTH credentials should result in failures. env GOAUTH='off'