I am trying to install a go package from a local directory (basically I checked out and existing package and applied a pending pull request).
$ # Both commands give a similar output
$ go get -u file:///Users/me/workspaces/go/somepackage
$ go get -u /Users/me/workspaces/go/somepackage
unrecognized import path "[...]" (import path does not begin with hostname)
Since go get
is downloading then installing, I tried:
$ go install /Users/me/workspaces/go/somepackage
[] cannot import absolute path
Any experienced go user could give a hand?
As far as I know you can't do this with go get
, bur you can copy the directory in to GOPATH manually. If you forked example.com/somepackage
then copy /Users/me/workspaces/go/somepackage
to ~/go/src/example.com/somepackage
or ./vendor/example.com/somepackage
.
That being said, the best solution is usually to host the forked code somewhere, and then use that import path. Decency tools such as dep and modules support fetching a different origin for packages.
I could be wrong and maybe there is a workaround exists
Go documentantion on cmd/go/#hdr-Remote_import_paths says:
The supported version control systems are:
Bazaar .bzr Fossil .fossil Git .git Mercurial .hg Subversion .svn
And a later:
For example,
import "example.org/pkg/foo"
will result in the following requests:
https://example.org/pkg/foo?go-get=1 (preferred)
http://example.org/pkg/foo?go-get=1 (fallback, only with -insecure)
So I suppose that go get
never looks in filesystem repos.
Need to investigate source code of go get
to be sure.
I will be glad if someone will prove that I am incorrect in this question.
Maybe I'm mistaken but I suppose that all abilities of go get
to work with VCSs are here: https://github.com/golang/go/blob/master/src/cmd/go/internal/get/vcs.go
And I don't see here a possibility to work with git local repos.
If you just want to use a different branch (your PR branch), you can continue using the original import path.
cd $GOPATH/pkg/<package directory>
git checkout <PR branch>
go get -u <package>
If the package is available locally, go get update will just pull the latest code from the branch your local package is checked out to.