git ls-remote成功,而go get失败。

huangapple go评论100阅读模式
英文:

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.gitssh://corp.example.com/repo.git的Git存储库,而无需进行其他请求。

请注意,VCS后缀是模块路径的一部分,因此应在使用模块路径的所有地方都包含它。包括:

  1. module指令

    module internal.net/dir1/dir2/dir3/repo.git
    
  2. require指令

    require internal.net/dir1/dir2/dir3/repo.git v0.0.1
    
  3. 导入声明

    import "internal.net/dir1/dir2/dir3/repo.git/pkg/util"
    
  4. 等等。

英文:

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:

  1. the module directive

    module internal.net/dir1/dir2/dir3/repo.git
    
  2. the require directive

    require internal.net/dir1/dir2/dir3/repo.git v0.0.1
    
  3. the import declaration

    import "internal.net/dir1/dir2/dir3/repo.git/pkg/util"
    
  4. and more.

huangapple
  • 本文由 发表于 2023年5月13日 15:40:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定