8

I'm trying to get a specific package from github for a project.

However, when I use go get [url] or go mod vendor, I get a git fetch error for lack of permissions to one of my company's repos. This repo is vendored, which is how we get around it for go test, go build etc.

This is the error message:

go: private.work.repo.com/project/repo@v0.0.0-20190703160253-9c6eb80851f1: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in C:\Users\NICHOLAS.TAN\go\pkg\mod\cache\vcs\37594aeb10b98234e04b4780cf59f32c4ad7bb9da460f552103ae748cea73aa1: exit status 128:
        fatal: remote error: Repository not found
        The requested repository does not exist, or you do not have permission to
        access it.

Is there a way for me to use go get and/or go mod vendor without those commands trying to look at the other module dependencies?

kozmo
  • 4,024
  • 3
  • 30
  • 48
ozma
  • 349
  • 1
  • 3
  • 10
  • cant you use `go get ` for packages you need? – whitespace Jul 23 '20 at 05:07
  • What's your go version? Could you paste the result of `go env`? – hyz Jul 23 '20 at 05:11
  • 1
    Using `GOPRIVATE=*.corp.com go get [url]` would exclude `*.corp.com` from go modules proxy which is a common reason for fetch problems from private repos. – Dmitry Verhoturov Jul 23 '20 at 08:02
  • @whitespace I will update question to be more clear, but issue is that if my project has a dependent module 'A' that requires access to a private repo, when I try to 'go get B', I will get an error about not being able to access repo A. – ozma Jul 23 '20 at 08:53
  • @hyz my go version is 1.14.6, [here is my go env (with a little bit edited for work reasons)](https://pastebin.com/RGf6mhXP) – ozma Jul 23 '20 at 08:54
  • @DmitryVerhoturov I tried this but still seem to get the same error, weirdly enough. Not sure if I am using it wrong, this is the repo URL: ```git.companyname.com/project/....``` and I am using command ```go get [url] GOPRIVATE=*companyname.com``` – ozma Jul 23 '20 at 08:59
  • I think it should be the other way around: ENV variable then the command. `GOPRIVATE=*.companyname.com go get [url] ` or `export GOPRIVATE=*.companyname.com` once before doing go get. – Dmitry Verhoturov Jul 25 '20 at 11:22

2 Answers2

4

You can get specific version of package use go get <package>@<version> in your project directory, for example:

% go get github.com/golang/protobuf@v1.4.0 

go: downloading github.com/golang/protobuf v1.4.0

Go download only get github.com/golang/protobuf package required version to local cache ($GOPATH/pkg/mod) and set version to go.mod file.

After all, if you have dependencies from your company's repos in local cache ($GOPATH/pkg/mod), use go mod vendor to create vendor (Go get ones from cache).

John Smith
  • 7,243
  • 6
  • 49
  • 61
kozmo
  • 4,024
  • 3
  • 30
  • 48
  • 1
    Thank you, however the issue isn't that I can't get a specific version, but that it tries to fetch dependencies that are already there while trying to ```go get``` a new one, which is causing problems because I don't have access to all of those dependencies. – ozma Jul 23 '20 at 09:00
  • I tried this one (get a specific version) without access to my company's private repo it works (private repo dependencies was located in my local cache) – kozmo Jul 23 '20 at 11:51
  • @ozma - Do you use modules or old approach? – kozmo Jul 24 '20 at 02:45
  • 1
    @ozma Did you find a solution ? – Sankar Jan 05 '21 at 14:26
  • 1
    @Sankar Sorry, I can't recall clearly any more, but I think I just temporarily manually removed those files from the go.mod/go.sum, ran the commands, and then added them back. – ozma Jan 13 '21 at 10:48
  • can something similar be done if you want to get a specific branch from a repo? using your example, what if there was a `dev` branch of protobuf, how would you go along trying to get that specific branch, possibly for testing purposes? – Keith E. Truesdell Mar 16 '23 at 02:08
1

This kind of issues will occur while getting private module and please check below configuration already done in your local system

Update git global config url

 git config --global --add url."git@github.com:".insteadOf "https://github.com/"  

Update go env to access private go module

go env -w GOPRIVATE=github.com/abc/*

Then run installation command

Mani Ezhumalai
  • 379
  • 2
  • 8