New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: improve error message if remote repo does not support https #27088

Open
shoenig opened this Issue Aug 19, 2018 · 10 comments

Comments

Projects
None yet
6 participants
@shoenig
Contributor

shoenig commented Aug 19, 2018

What version of Go are you using (go version)?

[k9 libconfig (master)] $ go version
go version devel +bf80e3b564 Sat Aug 18 18:23:06 2018 +0000 linux/amd64

What did you do?

With go1.11, run go build with modules and got unexpected "unknown revision" errors.
First, the go.mod file:

[k9 libops (master)] $ cat go.mod 
module code.corp.indeed.com/gophers/libops

require (
	code.corp.indeed.com/gophers/3rdparty v0.0.1
	code.corp.indeed.com/gophers/libconfig v0.0.1
)

replace (
	code.corp.indeed.com/gophers/3rdparty => ../../gophers/3rdparty
	code.corp.indeed.com/gophers/libconfig => ../../gophers/libconfig
)

Now let's try to build it:

[k9 libops (master)] $ go build
go: finding code.corp.indeed.com/gophers/rlog v0.0.1
go: finding code.corp.indeed.com/gophers/libtest v0.0.1
go: code.corp.indeed.com/gophers/libtest@v0.0.1: unknown revision v0.0.1
go: code.corp.indeed.com/gophers/rlog@v0.0.1: unknown revision v0.0.1
go: error loading module requirements

After lots of digging and head scratching, downloaded Go, modified the source to print more verbose logging in the modfetch package, and found the root cause:

[k9 libops (master)] $ go build
go: finding code.corp.indeed.com/gophers/libtest v0.0.1
seth: stat: rev: v0.0.1
seth: gitrepo remote: https://code.corp.indeed.com/gophers/libtest.git
seth: gitrepo local: false
seth: gitrepo dir: /home/hoenig/Documents/go/pkg/mod/cache/vcs/26c2c72546174752cc7dd33aee0e9fd20922ec3bdd500d96cff072028e4d56c7
seth: gitrepo fetchLevel: 0
seth: gitrepo refs: map[]
seth: gitrepo localTags: map[]
seth: stat: didStatLocal after local hash check: false
go: finding code.corp.indeed.com/gophers/rlog v0.0.1
seth: stat: rev: v0.0.1
seth: gitrepo remote: https://code.corp.indeed.com/gophers/rlog.git
seth: gitrepo local: false
seth: gitrepo dir: /home/hoenig/Documents/go/pkg/mod/cache/vcs/8a62f5a595067cf184b8895a656492a5c7cd608500e537286869c3267fa57765
seth: gitrepo fetchLevel: 0
seth: gitrepo refs: map[]
seth: gitrepo localTags: map[]
seth: stat: didStatLocal after local hash check: false
seth: stat: loadLocalTags did not find local, r.localTags: map[]
seth: stat: now checking if name of tag or branch on remote server
seth: load-refs: entering
seth: stat: loadLocalTags did not find local, r.localTags: map[]
seth: stat: now checking if name of tag or branch on remote server
seth: load-refs: entering
seth: loadRefs: git ls-remote failed:  https://code.corp.indeed.com/gophers/rlog.git git ls-remote -q https://code.corp.indeed.com/gophers/rlog.git in /home/hoenig/Documents/go/pkg/mod/cache/vcs/8a62f5a595067cf184b8895a656492a5c7cd608500e537286869c3267fa57765: exit status 128:
	fatal: could not read Username for 'https://code.corp.indeed.com': terminal prompts disabled
seth: just did loadRefs
seth: gitrepo remote: https://code.corp.indeed.com/gophers/rlog.git
seth: gitrepo local: false
seth: gitrepo dir: /home/hoenig/Documents/go/pkg/mod/cache/vcs/8a62f5a595067cf184b8895a656492a5c7cd608500e537286869c3267fa57765
seth: gitrepo fetchLevel: 0
seth: gitrepo refs: map[]
seth: gitrepo localTags: map[]
seth: now entering big if-else tree, refs: map[]
seth: exiting stat without finding rev: v0.0.1
go: code.corp.indeed.com/gophers/rlog@v0.0.1: unknown revision v0.0.1
seth: loadRefs: git ls-remote failed:  https://code.corp.indeed.com/gophers/libtest.git git ls-remote -q https://code.corp.indeed.com/gophers/libtest.git in /home/hoenig/Documents/go/pkg/mod/cache/vcs/26c2c72546174752cc7dd33aee0e9fd20922ec3bdd500d96cff072028e4d56c7: exit status 128:
	fatal: could not read Username for 'https://code.corp.indeed.com': terminal prompts disabled
seth: just did loadRefs
seth: gitrepo remote: https://code.corp.indeed.com/gophers/libtest.git
seth: gitrepo local: false
seth: gitrepo dir: /home/hoenig/Documents/go/pkg/mod/cache/vcs/26c2c72546174752cc7dd33aee0e9fd20922ec3bdd500d96cff072028e4d56c7
seth: gitrepo fetchLevel: 0
seth: gitrepo refs: map[]
seth: gitrepo localTags: map[]
seth: now entering big if-else tree, refs: map[]
seth: exiting stat without finding rev: v0.0.1
go: code.corp.indeed.com/gophers/libtest@v0.0.1: unknown revision v0.0.1
go: error loading module requirements

Note that it is incorrect to assume the remote will support https. At least some enterprise internal git hosting infrastructures are locked down to support ssh only. This was a common complaint about the dep tool as well.

Also note this was impossible to diagnose without hacking on the Go source code. We probably shouldn't suppress that error message.

@agnivade

This comment has been minimized.

Member

agnivade commented Aug 20, 2018

I think this was always the behavior - https://tip.golang.org/doc/faq#git_https.

Could you try the workaround suggested there and see if it works for you ?

@shoenig

This comment has been minimized.

Contributor

shoenig commented Aug 20, 2018

The

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/

workaround does work. The error message may want to point to that documentation.

@agnivade agnivade changed the title from cmd/go: go mod assumes https for remote repos, suppressed errors are impossible to diagnose to cmd/go: improve error message if remote repo does not support https Aug 20, 2018

@agnivade agnivade added this to the Go1.12 milestone Aug 20, 2018

@agnivade

This comment has been minimized.

Member

agnivade commented Aug 20, 2018

@rasky

This comment has been minimized.

Member

rasky commented Aug 20, 2018

Duplicate of #26134

@rasky rasky marked this as a duplicate of #26134 Aug 20, 2018

@rasky rasky closed this Aug 20, 2018

@shoenig

This comment has been minimized.

Contributor

shoenig commented Aug 25, 2018

@rasky @bcmills @rsc Can this be re-opened? While native support for non-https repos is one thing, this generic error message is totally useless and is showing up in additional contexts, hiding critical debugging information.

For example here is a problem with Goland vs. the Go command (probably environment related, but other than "unknown revision", there's no useful information.)

modloadreqs

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 25, 2018

Reopening.

@bcmills

This comment has been minimized.

Member

bcmills commented Nov 14, 2018

There are a bunch of interrelated issues with private repos; I'm planning to revisit that whole cluster for 1.13.

@bcmills bcmills added the GoCommand label Nov 14, 2018

@yanyandenuonuo

This comment was marked as off-topic.

yanyandenuonuo commented Nov 29, 2018

I add config in ~/.gitconfig

[url "ssh://gitlab@gitlab.domain.com:"]
	insteadOf = https://gitlab.domain.com/

but it not working. I try with go get -v gitlab.domain.com/xxx/xxx.git, i got errors:

Please make sure you have the correct access rights
and the repository exists.
# cd .; git ls-remote ssh://gitlab.domain.com/opgo/golib

i try at terminal git ls-remote ssh://gitlab@gitlab.domain.com/opgo/golib it works.

it show that the failed reason is less “gitlab@

how can i fix it?

i had try other config in ~/.gitconfig, but all failed

[url "gitlab@gitlab.domain.com:"]
	insteadOf = https://gitlab.domain.com/
[url "git@gitlab.domain.com:"]
	insteadOf = https://gitlab.domain.com/
@bcmills

This comment was marked as off-topic.

Member

bcmills commented Nov 29, 2018

@yanyandenuonuo, your configuration issue does not seem to be related to the topic of this issue (which is the quality of error messages produced by the go command).

See https://github.com/golang/go/wiki/Questions for more appropriate venues.

@yanyandenuonuo

This comment has been minimized.

yanyandenuonuo commented Nov 30, 2018

@bcmills it's cause go get can't use the ssh protocol, so i comment at this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment