aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modfetch/codehost/git.go
diff options
context:
space:
mode:
authorKevin Burke <kevin@burke.dev>2021-03-02 11:54:36 -0800
committerKevin Burke <kev@inburke.com>2021-03-05 20:15:19 +0000
commit39bdd41d03725878f1fd6f8b500ba6700f03bdad (patch)
tree7c3203dc7263dbded5a4834109d7de23137cecf9 /src/cmd/go/internal/modfetch/codehost/git.go
parent44721f4565858526545c69b4846daeea40843a98 (diff)
downloadgo-39bdd41d03725878f1fd6f8b500ba6700f03bdad.tar.gz
go-39bdd41d03725878f1fd6f8b500ba6700f03bdad.zip
cmd/go/internal/modfetch/codehost: report git errors more accurately
Previously, if you attempted to fetch a private repository, or your Git/curl client failed for an unknown reason, codehost would return an UnknownRevisionError, which reported that a given revision in go.mod was "unknown". This is confusing to many users who can go look in their browser for example and see that the commit-ish exists. Instead check whether "git ls-remote" exited with an error, and if so, return that instead of the UnknownRevision message. Fixes #42751. Change-Id: I0dbded878b2818280e61126a4493767d719ad577 Reviewed-on: https://go-review.googlesource.com/c/go/+/297950 Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modfetch/codehost/git.go')
-rw-r--r--src/cmd/go/internal/modfetch/codehost/git.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index 72005e27d5..4d4964edf4 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -296,6 +296,9 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
// Or maybe it's the prefix of a hash of a named ref.
// Try to resolve to both a ref (git name) and full (40-hex-digit) commit hash.
r.refsOnce.Do(r.loadRefs)
+ // loadRefs may return an error if git fails, for example segfaults, or
+ // could not load a private repo, but defer checking to the else block
+ // below, in case we already have the rev in question in the local cache.
var ref, hash string
if r.refs["refs/tags/"+rev] != "" {
ref = "refs/tags/" + rev
@@ -332,6 +335,9 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
hash = rev
}
} else {
+ if r.refsErr != nil {
+ return nil, r.refsErr
+ }
return nil, &UnknownRevisionError{Rev: rev}
}