Home  >  Article  >  Backend Development  >  git ls-remote succeeds but go get fails

git ls-remote succeeds but go get fails

WBOY
WBOYforward
2024-02-14 13:54:08427browse

git ls-remote 成功而 go get 失败

php editor Apple encountered a problem when using Git and Go language to develop projects: the git ls-remote command can successfully obtain the information of the remote warehouse, but using the go get command fails Unable to successfully download dependent packages. This problem has troubled the editor for a long time. After constant attempts and debugging, I finally found a solution. In this article, we will introduce the cause and solution of this problem in detail, hoping to be helpful to developers who encounter the same problem.

Question content

The git ls-remote command is successful for the repository 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 using go get, cmd fails and cannot find the repository. The error output is trying to find .git in 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 privatization is goprivate=internal.net

What am I missing here in order for go get to succeed?

Solution

Add the vcs suffix in 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 required to resolve module paths into repository urls . For example, when the go command downloads module corp.example.com/mod, it sends a get to https://corp.example.com/mod?go-get=1 request and will look for the url in the repository response. To avoid this requirement, make sure each private module path has a vcs suffix (such as .git) marking the repository root prefix. For example, when the go command downloads module corp.example.com/repo.git/mod, it will clone it at https://corp.example.com/repo.git or ssh://corp.example's git repository.com/repo.git without making additional requests.

Please note that the vcs suffix is ​​part of the module path, so it should be included wherever the module path is used. include:

  1. module Command

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

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

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

The above is the detailed content of git ls-remote succeeds but go get fails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete