We have two versions of a go module hosted by different people. Let's call them example.org/devproject
and company.com/project
. Different programs obviously import the two projects by different import paths, as appropriate, depending on whether they want the version maintained by example.org or company.com. Because the modules have numerous internal packages, the source files themselves contain references to their own module's name in many import statements.
My question is how example.org can make it as easy as possible for company.com to pull from our git repository, because right now a straight git pull messes up the import statements. Note that stack overflow has similar questions on this prior to go modules. However, this question is specifically about projects with go.mod files using go 1.11 or later, so please do not refer me to non-module answers or suggest not using go modules yet, because that is a different question.
I've tried the following that unfortunately do not work super well:
Use some abstract module name like
module self
in thego.mod
file and addreplace self => example.org/devproject
. Then internal packages can justimport "self/subpackage"
, and only the onereplace
line needs to change between repositories. However, that means all including projects need to use areplace
directive, and we'd need to convince company.com to change all of their imports relative to "self", which isn't super likely. More importantly, this totally breaksgo get
and is probably a bad idea.Use semi-automated scripts to maintain a git branch
pull-me
that is always exactly one commit ahead ofmaster
but has all the import paths andgo.mod
file fixed up for company.com. This is what we currently do, but it's annoying because the scripts don't know how to parse go source code, so just blindly replaceexample.org/devproject
withcompany.com/project
everywhere, meaning there is no guarantee that just becausemaster
workspull-me
will, too. We somehow can't getgomvpkg
working in a go module outside of a gopath (it will change package statements, but not the imports, which are the tricky part, and won't recurse into all the subpackages).Create a fake gopath, copy the master branch into it, use
gomvpkg
to move stuff, then copy the files back with a revised import path, then delete the fake gopath. I can't 100% rule this out, but I gave up aftergomvpkg
just kept refusing to do the right thing and I got frustrated that something so conceptually simple was so difficult to make work in practice.
Are there any other solutions we should be considering? Are there any tools like govmpkg
that understand go modules and will rewrite import paths without also trying to move stuff around in a gopath?
As is probably clear, the dynamics here are that example.org is much more motivated to get stuff upstreamed than company.com is to pull from us, so ideally most of the hoop jumping would happen on the example.org side, and there would maybe be a one-time simple non-intrusive request to company.com to do something to make this work.