git ls-remote succeeds but go get fails

WBOY
Release: 2024-02-14 13:54:08
forward
279 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
    Copy after login
  2. require Command

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

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

  5. 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!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!