cmd/go/internal/modfetch/gitrepo: work around old git fetch hash behavior For the git fetch --depth=1 attempt: 1. Use a ref instead of a hash if known. 2. Check for the older "no such remote ref" error in addition to the newer "unadvertised object" error. Fixes golang/go#25102. Change-Id: I38e66237c94c53989729bc0adf094980aaaf9093 Reviewed-on: https://go-review.googlesource.com/109518 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go b/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go index 1e8345b..635f1a0 100644 --- a/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go +++ b/vendor/cmd/go/internal/modfetch/gitrepo/fetch.go
@@ -251,10 +251,14 @@ // Fetch it. if len(hash) == 40 { - if _, err = codehost.Run(r.dir, "git", "fetch", "--depth=1", r.remote, hash); err == nil { + name := hash + if ref, ok := r.findRef(hash); ok { + name = ref + } + if _, err = codehost.Run(r.dir, "git", "fetch", "--depth=1", r.remote, name); err == nil { goto Found } - if !strings.Contains(err.Error(), "unadvertised object") { + if !strings.Contains(err.Error(), "unadvertised object") && !strings.Contains(err.Error(), "no such remote ref") { return nil, nil, err } }