golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.88k stars 17.52k forks source link

go get could not understand the right git path. it only support one level namespace #21859

Closed ghost closed 7 years ago

ghost commented 7 years ago

I am try to using go get tool to download golang packages.

 go get -u -v www.gitexample.com/comnap/public_service/short_url    
Fetching https://www.gitexample.com/comnap/public_service/short_url?go-get=1
Parsing meta tags from https://www.gitexample.com/comnap/public_service/short_url?go-get=1 (status code 200)
get "www.gitexample.com/comnap/public_service/short_url": found meta tag get.metaImport{Prefix:"www.gitexample.com/comnap/public_service", VCS:"git", RepoRoot:"https://www.gitexample.com/comnap/public_service.git"} at https://www.gitexample.com/comnap/public_service/short_url?go-get=1
get "www.gitexample.com/comnap/public_service/short_url": verifying non-authoritative meta tag
Fetching https://www.gitexample.com/comnap/public_service?go-get=1
Parsing meta tags from https://www.gitexample.com/comnap/public_service?go-get=1 (status code 200)
www.gitexample.com/comnap/public_service (download)
# cd .; git clone https://www.gitexample.com/comnap/public_service.git /home/huzhifeng/go/src/www.gitexample.com/comnap/public_service
Cloning into '/home/huzhifeng/go/src/www.gitexample.com/comnap/public_service'...
Warning: Permanently added 'www.gitexample.com,192.168.13.123' (ECDSA) to the list of known hosts.
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

the prefix was /compnap/public_service . And the short_url was the real project name. But golang try to located comnap/public_service as git repository. It really not good for us.

Why go get can only support one level path?

ghost commented 7 years ago

In our real production environment, we have thousands repositories. we need to organize them in 3 or 4 level. Such as

gitexample.com/comap/graph/composite
gitexample.com/comap/compress/xmodzip

They are standalone git repository, and maintained by different department.

Merovius commented 7 years ago

AIUI, the repository you are trying to clone is at https://www.gitexample.com/comnap/public_service/short_url.git? In that case, the meta-tag served at https://www.gitexample.com/comnap/public_service/short_url should be:

<meta name="go-import" content="www.gitexample.com/comnap/public_service/short_url git https://www.gitexample.com/comnap/public_service/short_url.git">

But it seems to be

<meta name="go-import" content="www.gitexample.com/comnap/public_service git https://www.gitexample.com/comnap/public_service.git">

leading go get to make the extra request for https://www.gitexample.com/comnap/public_service?go-get=1, which serves the meta-tag

<meta name="go-import" content="www.gitexample.com/comnap/public_service git https://www.gitexample.com/comnap/public_service.git">

so go-get tries to clone that.

Whatever is serving https://www.gitexample.com/ needs to fix the meta-tags it is serving to point to the correct repository. See here for the protocol used. In particular, if you want to make a sub-directory of a repository go-gettable, vcs-prefix needs to be the import-path of the repository root and repo-root should be where to clone the repository from. So, you want to set up the server to serve the meta tag

<meta name="go-import" content="www.gitexample.com/comnap/public_service/short_url git https://www.gitexample.com/comnap/public_service/short_url.git">

on all urls starting with https://gitexample.com/comnap/public_service/short_url.

Does that help?

ghost commented 7 years ago

I checked the <meta, There is no <meta name="go-import" section.

Merovius commented 7 years ago

Have you tried including the ?go-get=1? Because the log claims it found a meta-tag. (I would help verifying, but the domain does not resolve for me, apparently)

Merovius commented 7 years ago

Try curl https://www.gitexample.com/comnap/public_service/short_url?go-get=1 | grep go-import (that's the url the log says it fetches). When I try to use go-get with a path that does not serve a meta-tag, it reports correctly that there is no meta-tag.

ianlancetaylor commented 7 years ago

I'm going to close this issue because I don't see any fixable bug here. Please comment if you disagree. If you don't understand the meta-tag protocol that @Merovius mentions, please ask a on a forum; see https://golang.org/wiki/Questions. Thanks.

arizonahanson commented 6 years ago

I am having this exact issue. pretty critical for me right now: (company dns/folder/project name changed) my meta tag: <meta name="go-import" content="my.gitlab.com/top/sub/project git https://my.gitlab.com/top/sub/project.git" />

but it doesn't like the extra level it seems:

found meta tag get.metaImport{Prefix:"my.gitlab.com/top/sub", VCS:"git", RepoRoot:"https://my.gitlab.com/top/sub.git"} at https://my.gitlab.com/top/sub/project?go-get=1

I realize a real fix would have to wait for the next release, but if I could get a workaround for it, it would be a huge help.

arizonahanson commented 6 years ago

Ignore me. Gitlab issue.