0

I have a project where I use go modules. There I need to specify that I depend on a particular fork of a library (call it ), because it has an important patch. When I run go get -u <my_project>, I get a compilation error that clearly means that go took the main repo of , instead of the fork.

After that, I switch to the directory where go downloaded and run go build. Then, go takes the proper version of and compilation is successful.

Could you tell me what could be the reason for that and how to fix it?

Here is specific command to get :

go get -u github.com/planetA/konk

The dependency is "github.com/opencontainers/runc". For this dependency, go.mod contains following:

replace (
   github.com/opencontainers/runc => github.com/planeta/runc v1.0.0-rc9.0.20191206160324-51eabe724369
)

require (
   github.com/opencontainers/runc v1.0.0-rc9.0.20191206223258-201b06374548
)

Interestingly, in following sequence of commands, second go get does not produce error

go get -u github.com/planetA/konk
cd ~/go/src/github.com/planetA/konk
go build -tags seccomp
go get -u github.com/planetA/konk
mcsim
  • 1,647
  • 2
  • 16
  • 35

1 Answers1

0

I had a similar problem and I resolved this by detaching the fork itself and making a separate repo. Depends on your use case, this is also a much cleaner solution as you don't need to add too many edits to make it work. You can do so by:

  • Clone the fork repository on your local.
  • Delete the fork repository from github/gitlab etc. if you want the package name to be the same as the fork if not you can rename the new repo you create.
  • Create a new repo and push your content onto it
  • Now go get github.com/myusername/mynewrepo

But if you still want to make it work using the fork here is a great reference.

Gopherine
  • 1,021
  • 12
  • 24
  • Sorry, I'm not sure I understand items 1 and 2. – mcsim Dec 13 '19 at 09:22
  • 1
    @mcsim Sorry for bad english basically you have to git clone your forked repository and then push the same to a seperate repo which is completely detached from the original master branch where you forked it from now you can either make this new repository with a different name or delete the repository you forked and create it with same name then when you perform go get on this new repo it will likely work. – Gopherine Dec 13 '19 at 09:50
  • Thank you. But that looks more like a workaround. I believe that "go get" should be enough otherwise something is wrong with the module system. I will consider submitting bug report if I don't find some other solution. – mcsim Dec 13 '19 at 12:33
  • I did say its a workaround but the link I gave you there mention it there is no direct way of getting a fork by simply go get however he in his blog gives you detailed information on how to make it work :) also it's not a bug you will have to report this as a feature request instead – Gopherine Dec 13 '19 at 12:37
  • 1
    For me this look more and more like a bug, because "go build" works without a hassle. I could just do "git clone" and then "go build" and then "go install". "go get" is supposed to do the same with the same effect. But apparently, the effect is different. – mcsim Dec 13 '19 at 12:44