从Azure DevOps存储库导入时,由于缺少.git文件,导致无法获取私有存储库。

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

go get private repo fails due to missing .git when importing from Azure DevOps repositories

问题

我正在尝试将一个私有仓库安装为 golang 模块。

在阅读了 Microsoft 的博客文章之后,我尝试在本地进行操作。

我已经更新了本地的 .gitconfig 文件:

insteadOf = https://dev.azure.com/<my org>/

并且导出到了我的环境变量中:

export GOPRIVATE=dev.azure.com/<my org>/

该仓库包含一个带有以下头部的 go.mod 文件:

module dev.azure.com/<my-org>/<project>/<repo>

go 1.18

当我尝试通过以下命令安装模块时:

go get -v dev.azure.com/<my-org>/<project>/<repo>.git@develop

它会失败,并显示以下错误信息:

go: dev.azure.com/<my-org>/<project>/<repo>.git@v0.0.0-20220827174211-d4e6ad2f92b0: parsing go.mod:
        module declares its path as: dev.azure.com/<my-org>/<project>/<repo>
                but was required as: dev.azure.com/<my-org>/<project>/<repo>.git

然而,如果我删除末尾的 .git,它会失败并显示以下信息:

203 Non-Authoritative Information

请问导入私有模块的正确方式是什么?

英文:

I'm attempting to install a private repository as a golang module.

After reading the Microsoft blog post. I've attempted to do it locally.

I've updated the local .gitconfig with

insteadOf = https://dev.azure.com/&lt;my org&gt;/

Also exported to my environment:

export GOPRIVATE=dev.azure.com/&lt;my org&gt;/

The repository contains a go.mod file with the following header:

module dev.azure.com/&lt;my-org&gt;/&lt;project&gt;/&lt;repo&gt;

go 1.18

When I attempt to install the module via:

go get -v dev.azure.com/&lt;my-org&gt;/&lt;project&gt;/&lt;repo&gt;.git@develop

It fails with:

go: dev.azure.com/&lt;my-org&gt;/&lt;project&gt;/&lt;repo&gt;.git@v0.0.0-20220827174211-d4e6ad2f92b0: parsing go.mod:
        module declares its path as: dev.azure.com/&lt;my-org&gt;/&lt;project&gt;/&lt;repo&gt;
                but was required as: dev.azure.com/&lt;my-org&gt;/&lt;project&gt;/&lt;repo&gt;.git

However, if I remove the .git at the end it fails with:

> 203 Non-Authoritative Information

What's the appropriate way of importing private modules

答案1

得分: 1

删除 .git 是第一步。

203 错误在 golang/go 问题 41030 中提到,该问题重定向到 问题 28236

其中包括:

> 如果你因为使用 go get 与 Azure DevOps 仓库同步时遇到身份验证问题,例如在构建机器上,你可以在你的 gitconfig 文件中设置一个简单的 git 凭据助手,例如:
>
> [credential "https://dev.azure.com"]
> helper = "/bin/sh /etc/azure-devops-helper.sh"
>
> 其中 azure-devops-helper.sh 的内容类似于:
>
>bash &gt;#!/bin/sh &gt;echo username=$USERNAME &gt;echo password=$AZURE_DEVOPS_TOKEN &gt;
>
> 其中包含了包含用户名和 PAT 的环境变量。对于我们来说,这比切换到 Azure 仓库的 SSH 更可靠。

而对于任何 401 Gone 错误:

> 需要在 GOPRIVATE 中明确告知不要检查 dev.azure.com 的校验和。
>
> 看起来确实只是这个问题。

英文:

Removing .git is a first step.

The 203 error is mentioned in golang/go issue 41030, which redirects to issue 28236.

It includes:

> If you are here due to authentication issues sync'ing with Azure DevOps repos with go get, e.g. on a build machine then you can setup a simple git credential helper in your gitconfig file: e.g:
>
> [credential "https://dev.azure.com"]
> helper = "/bin/sh /etc/azure-devops-helper.sh"
>
>with azure-devops-helper.sh something like
>
>bash
&gt;#!/bin/sh
&gt;echo username=$USERNAME
&gt;echo password=$AZURE_DEVOPS_TOKEN
&gt;

>
>where environment variables containing the username and PAT taken.
This proved more reliable for us than switching to SSH for azure repos.

And, for any 401 Gone error:

> Needed to tell explicitly in GOPRIVATE to not to check checksums of dev.azure.com.
>
> It seems it was really only that.

huangapple
  • 本文由 发表于 2022年8月28日 02:10:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/73513343.html
匿名

发表评论

匿名网友

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

确定