英文:
git ls-remote succeeds while go get fails
问题
git ls-remote命令成功显示了一个仓库,如下所示。
git ls-remote https://internal.net/dir1/dir2/dir3/repo
warning: redirecting to https://internal.net/dir1/dir2/dir3/repo.git/
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HEAD
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy refs/heads/master
然而,当使用go get命令时,命令失败并显示找不到仓库的错误。错误输出尝试在仓库结构的上一级目录中找到.git。
go get internal.net/dir1/dir2/dir3/repo@master
go: internal.net/dir1/dir2/dir3/repo@master: invalid version: git ls-remote -q origin in /Users/{{UserId}}/go/pkg/mod/cache/vcs/xyz...: exit status 128:
remote: The project you were looking for could not be found or you don't have permission to view it.
fatal: repository 'https://internal.net/dir1/dir2.git/' not found
我的goprivate设置为
GOPRIVATE=internal.net
我在go get中漏掉了什么,以使其成功?
英文:
git ls-remote command succeeds for a repo as shown below.
git ls-remote https://internal.net/dir1/dir2/dir3/repo
warning: redirecting to https://internal.net/dir1/dir2/dir3/repo.git/
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HEAD
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy refs/heads/master
However, when go get is used the cmd fails with repository not found. The error output tries to find .git at 1 directory above the repository structure.
go get internal.net/dir1/dir2/dir3/repo@master
go: internal.net/dir1/dir2/dir3/repo@master: invalid version: git ls-remote -q origin in /Users/{{UserId}}/go/pkg/mod/cache/vcs/xyz...: exit status 128:
remote: The project you were looking for could not be found or you don't have permission to view it.
fatal: repository 'https://internal.net/dir1/dir2.git/' not found
My goprivate is
GOPRIVATE=internal.net
What am I missing here for the go get to succeed?
答案1
得分: 1
给私有模块路径添加一个VCS后缀,以标记存储库的根前缀:
go get internal.net/dir1/dir2/dir3/repo.git@master
参见直接访问私有模块:
> 仍然可能需要一个内部HTTP服务器来将模块路径解析为存储库URL。例如,当go命令下载模块corp.example.com/mod
时,它将向https://corp.example.com/mod?go-get=1
发送GET请求,并在响应中查找存储库URL。为了避免这个要求,请确保每个私有模块路径都有一个VCS后缀(如.git
),标记存储库的根前缀。例如,当go命令下载模块corp.example.com/repo.git/mod
时,它将克隆位于https://corp.example.com/repo.git
或ssh://corp.example.com/repo.git
的Git存储库,而无需进行其他请求。
请注意,VCS后缀是模块路径的一部分,因此应在使用模块路径的所有地方都包含它。包括:
-
module
指令module internal.net/dir1/dir2/dir3/repo.git
-
require
指令require internal.net/dir1/dir2/dir3/repo.git v0.0.1
-
导入声明
import "internal.net/dir1/dir2/dir3/repo.git/pkg/util"
-
等等。
英文:
Add a VCS suffix to the private module path to mark the repository root prefix:
go get internal.net/dir1/dir2/dir3/repo.git@master
See Direct access to private modules:
> An internal HTTP server may still be needed to resolve module paths to repository URLs. For example, when the go command downloads the module corp.example.com/mod
, it will send a GET request to https://corp.example.com/mod?go-get=1
, and it will look for the repository URL in the response. To avoid this requirement, ensure that each private module path has a VCS suffix (like .git
) marking the repository root prefix. For example, when the go command downloads the module corp.example.com/repo.git/mod
, it will clone the Git repository at https://corp.example.com/repo.git
or ssh://corp.example.com/repo.git
without needing to make additional requests.
Please note that the VCS suffix is a part of the module path, so it should be included in all the places where a module path is used. Including:
-
the
module
directivemodule internal.net/dir1/dir2/dir3/repo.git
-
the
require
directiverequire internal.net/dir1/dir2/dir3/repo.git v0.0.1
-
the import declaration
import "internal.net/dir1/dir2/dir3/repo.git/pkg/util"
-
and more.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论