From 9a11b7363589a20b8ba78a1fc02027198811b109 Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Tue, 20 Nov 2018 17:42:59 -0500 Subject: [PATCH] cmd/go: link to the FAQ for errors that indicate private VCS repos. Updates #25982 Change-Id: I5a284e3844e944f9bfae31fa65b242060d4139c7 Reviewed-on: https://go-review.googlesource.com/c/150777 Run-TryBot: Julie Qiu Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/modfetch/codehost/codehost.go | 10 +++++++--- src/cmd/go/internal/modfetch/codehost/git.go | 5 +++++ src/cmd/go/testdata/script/mod_get_private_vcs.txt | 10 ++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_get_private_vcs.txt diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go index 988504f4c8..6c17f7886f 100644 --- a/src/cmd/go/internal/modfetch/codehost/codehost.go +++ b/src/cmd/go/internal/modfetch/codehost/codehost.go @@ -196,9 +196,10 @@ func WorkDir(typ, name string) (dir, lockfile string, err error) { } type RunError struct { - Cmd string - Err error - Stderr []byte + Cmd string + Err error + Stderr []byte + HelpText string } func (e *RunError) Error() string { @@ -207,6 +208,9 @@ func (e *RunError) Error() string { if len(stderr) > 0 { text += ":\n\t" + strings.ReplaceAll(string(stderr), "\n", "\n\t") } + if len(e.HelpText) > 0 { + text += "\n" + e.HelpText + } return text } diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go index 7b3775779b..588e7496cc 100644 --- a/src/cmd/go/internal/modfetch/codehost/git.go +++ b/src/cmd/go/internal/modfetch/codehost/git.go @@ -164,6 +164,11 @@ func (r *gitRepo) loadRefs() { // Most of the time we only care about tags but sometimes we care about heads too. out, err := Run(r.dir, "git", "ls-remote", "-q", r.remote) if err != nil { + if rerr, ok := err.(*RunError); ok { + if bytes.Contains(rerr.Stderr, []byte("fatal: could not read Username")) { + rerr.HelpText = "If this is a private repository, see https://golang.org/doc/faq#git_https for additional information." + } + } r.refsErr = err return } diff --git a/src/cmd/go/testdata/script/mod_get_private_vcs.txt b/src/cmd/go/testdata/script/mod_get_private_vcs.txt new file mode 100644 index 0000000000..86d78e8381 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_get_private_vcs.txt @@ -0,0 +1,10 @@ +env GO111MODULE=on + +# Testing stderr for git ls-remote; turn off proxy. +[!net] skip +[!exec:git] skip +env GOPROXY= + +! go get github.com/golang/nonexist +stderr 'If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.' +! stdout . -- 2.50.0