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

1

6

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

[url "[email protected]:v3/<my org>/"]
  insteadOf = https://dev.azure.com/<my org>/

Also exported to my environment:

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

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

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

go 1.18

When I attempt to install the module via:

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

It fails with:

go: dev.azure.com/<my-org>/<project>/<repo>[email protected]: 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

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

Keijo answered 27/8, 2022 at 18:10 Comment(0)
F
1

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

#!/bin/sh
echo username=$USERNAME
echo password=$AZURE_DEVOPS_TOKEN

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.

Fiertz answered 30/8, 2022 at 20:26 Comment(2)
So the solution here is don't do what microsoft says and don't use ssh?Keijo
@Keijo Yes, you can test the HTTPS option from the same doc.Fiertz

© 2022 - 2024 — McMap. All rights reserved.