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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.