Skip to content

Commit 9a11b73

Browse files
committed
cmd/go: link to the FAQ for errors that indicate private VCS repos.
Updates golang#25982 Change-Id: I5a284e3844e944f9bfae31fa65b242060d4139c7 Reviewed-on: https://go-review.googlesource.com/c/150777 Run-TryBot: Julie Qiu <julie@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
1 parent d70b0ec commit 9a11b73

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/cmd/go/internal/modfetch/codehost/codehost.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ func WorkDir(typ, name string) (dir, lockfile string, err error) {
196196
}
197197

198198
type RunError struct {
199-
Cmd string
200-
Err error
201-
Stderr []byte
199+
Cmd string
200+
Err error
201+
Stderr []byte
202+
HelpText string
202203
}
203204

204205
func (e *RunError) Error() string {
@@ -207,6 +208,9 @@ func (e *RunError) Error() string {
207208
if len(stderr) > 0 {
208209
text += ":\n\t" + strings.ReplaceAll(string(stderr), "\n", "\n\t")
209210
}
211+
if len(e.HelpText) > 0 {
212+
text += "\n" + e.HelpText
213+
}
210214
return text
211215
}
212216

src/cmd/go/internal/modfetch/codehost/git.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func (r *gitRepo) loadRefs() {
164164
// Most of the time we only care about tags but sometimes we care about heads too.
165165
out, err := Run(r.dir, "git", "ls-remote", "-q", r.remote)
166166
if err != nil {
167+
if rerr, ok := err.(*RunError); ok {
168+
if bytes.Contains(rerr.Stderr, []byte("fatal: could not read Username")) {
169+
rerr.HelpText = "If this is a private repository, see https://golang.org/doc/faq#git_https for additional information."
170+
}
171+
}
167172
r.refsErr = err
168173
return
169174
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
env GO111MODULE=on
2+
3+
# Testing stderr for git ls-remote; turn off proxy.
4+
[!net] skip
5+
[!exec:git] skip
6+
env GOPROXY=
7+
8+
! go get github.com/golang/nonexist
9+
stderr 'If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.'
10+
! stdout .

0 commit comments

Comments
 (0)