英文:
Why does GO mod tidy not work with bitbucket
问题
我正在尝试将私有仓库用作Go库。
每当我尝试运行"go get"或"go mod tidy"时,都会出现以下错误:
> go get bitbucket.org/myworkspace/myRepo
go get bitbucket.org/myworkspace/myRepo: 读取 https://api.bitbucket.org/2.0/repositories/myworkspace/myRepo?fields=scm: 404 Not Found
我找到了多个修复此问题的建议,包括使用git config insteadOf url重写,但这些方法都不起作用。所有这些方法都假设Go会通过git克隆库存储库,而不是使用API。
我的同事在运行Linux的机器上尝试了这个方法,它可以正常工作,并且在任何时候都没有使用api.bitbucket.org,而只是使用bitbucket.org。
我尝试使用Insomnia调用https://api.bitbucket.org/2.0/repositories/myworkspace/myRepo?fields=scm,并提供了凭据,结果可以成功获取到仓库。
为什么在Windows上使用的是Bitbucket API?我该如何使用凭据让Go能够找到该仓库?
英文:
I'm attempting to use private repositories as go libraries.
Whenever i try to run go get og god mod tidy, i get this kind of error
>go get bitbucket.org/myworkspace/myRepo
go get bitbucket.org/myworkspace/myRepo: reading https://api.bitbucket.org/2.0/repositories/myworkspace/myRepo?fields=scm: 404 Not Found
I've found multiple suggestions to fix this, with git config insteadOf url reqriting, but it doesn't work, and it all seems to assume that go will clone the library repo via git, and not the api.
My colleague who is running Linux, tried this and it worked, and at no point does it appear to use api.bitbucket.org instead of just bitbucket.org.
I've tried calling https://api.bitbucket.org/2.0/repositories/myworkspace/myRepo?fields=scm via Insomnia, with credentials, and i get the repo back just fine.
Why does go use the bitbucket api on windows, and how can i have it use credentials, so it can find the repo ?
答案1
得分: 2
这是由Bitbucket进行的更改导致的(从2022年6月1日开始推出):
> 这些更改将破坏先前版本的Go,因为go命令依赖于403响应来获取托管在Bitbucket Cloud上的存储库。这意味着使用旧版本Go的用户(例如具有Go依赖项的CI/CD构建)将遇到404错误。
Go已经更新以支持这些更改;版本1.18包含了这个更改,但如果您正在运行早期版本,您可能需要升级到较新的次要修订版(更改在1.17.7
和1.16.14
中)。相关的Go问题在这里(更改的目的是不同的,但它解决了这个问题)。
> 为什么go在Windows上使用bitbucket api...
Go使用API来确定Bitbucket存储库是否使用Git或Mercurial(Bitbucket正在停止支持Mercurial)。
正如在评论中提到的,我发现新的Git凭据管理器消除了以前访问私有Bitbucket存储库所需的解决方法。只需使用凭据管理器并设置GOPRIVATE
即可。
英文:
This is due to a change made by Bitbucket (rolling out from June 1st 2022):
>Rolling out these changes will break previous versions of Go due to the fact that the go command relies on a 403 response to fetch repositories hosted on Bitbucket Cloud. This means that users who use older versions of Go with private repositories, for example CI/CD builds with Go dependencies, will run into 404 errors.
Go has been updated to support these changes; version 1.18 includes the change but if you are running an earlier version you may need to upgrade to a later minor revision (change is in 1.17.7
and 1.16.14
). The relevant Go issue is here (the aim of the change is something different but it resolves the issue).
>Why does go use the bitbucket api on windows...
Go was using the API to determine if the Bitbucket repo was using Git or Mercurial (Bitbucket is dropping support for Mercurial).
As mentioned in the comments I've found that the new Git Credential Manager removes the need for the workarounds previously required to access private Bitbuicket repos. Using the credential manager and setting GOPRIVATE
was all that was needed..
答案2
得分: 1
你可以使用命令export GOPRIVATE=<远程模块名称>
来首先导出私有仓库。然后,你可以运行命令env GIT_TERMINAL_PROMPT=1 go get <远程模块名称>
,这样如果未配置凭据,你将会收到一个提示。
英文:
You can first export the private repository with the command export GOPRIVATE=<remote module name>
. Then you can run the command env GIT_TERMINAL_PROMPT=1 go get <remote module name>
so that if the credentials are not configured, you get a prompt.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论