Go dep and forks of libraries

老子叫甜甜 提交于 2019-12-02 17:28:16

问题


I'm trying to understand how to work with Golang and forks. The situation is the following, I'm writing a library project which depends on library github.com/other/some_dependency, which isn't mine.

Because some_dependency is missing some methods that I need, I fork it to github.com/me/some_dependency. However, I can't just do go get github.com/me/some_dependency, the library references itself so it breaks.

In this article they give a possible solution:

 go get github.com/other/some_dependency
 cd $GOPATH/src/github.com/other/some_dependency
 git remote add fork git@github.com:me/some_dependency
 git rebase fork/master

Now, this is hacky at best. There is no way from the code of the library to know that the dependency is coming from a different repo. Anyone doing go get of my library wouldn't manage to make it work.

As dep is expected to be the official dependency manager. I've found how to fix the version:

dep ensure -add github.com/foo/bar@v1.0.0

But I cannot find how to set a different remote. Is is possible to do it? As an example, in Node.js with npm it is dead simple:

npm install git+https://git@github.com/visionmedia/express.git

回答1:


If you look at the help you will see this:

<import path>[:alt source URL][@<constraint>]

So to add github.com/foo/bar from location github.com/fork/bar you have to add it like this:

dep ensure -add github.com/foo/bar:github.com/fork/bar

The source location will be added as source attribute in the Gopkg.toml.

Gopkg docs for dependency rules constraint and override



来源:https://stackoverflow.com/questions/49475290/go-dep-and-forks-of-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!