I think you should be able to do `go get ./... dep1@branchA dep2@branchB 
...`
On Friday, November 6, 2020 at 3:20:16 PM UTC+1 Jim Minter wrote:

> Hi,
>
> Using Go 1.14, I'm working on a parent codebase which, in its go.mod 
> file, has a number of replace statements referencing legacy child 
> codebases which have not yet converted to Go modules.
>
> At this stage the legacy child codebases handle versioning by branch, 
> rather than using semantic versioning, so my go.mod file has a number of 
> statements like these:
>
> > replace github.com/foo/bar => github.com/foo/bar 
> v0.0.0-2020xxxxxxxxxx-hhhhhhhhhhhh // should track branch baz
> > replace github.com/foo/bar1 => github.com/foo/bar1 
> v0.0.0-2020yyyyyyyyyy-iiiiiiiiiiii // should track branch baz
>
> My goal is to be confident that if I update dependencies in the parent 
> codebase (go get -u ./...), I'll be pulling in HEAD on the relevant 
> branch of all the legacy child dependencies.
>
> My expectation is that this is a transitional use case because 
> eventually the child codebases will migrate to Go modules, but until 
> then, it's important to me to know I will pull in critical fixes from 
> the child dependencies if they happen.
>
> The difficulty I've got is ensuring that the replace stanzas are valid 
> and up-to-date. I'm not finding a great way to do this with the Go 
> module tooling and I wonder if I'm missing anything. Here are the 
> feasible ugly alternatives I've found so far:
>
> 1. Child by child, abuse the fact that `go mod tidy` rightly or wrongly 
> seems to tolerate a single legacy branch reference in the file at a time 
> and rewrites it to the v0.0.0-2020xxxxxxxxxx-hhhhhhhhhhhh format:
>
> > go mod edit -replace github.com/foo/bar=github.com/foo/bar@baz
> > go mod tidy
> > go mod edit -replace github.com/foo/bar1=github.com/foo/bar1@baz
> > go mod tidy
> > ...etc...
> > go get -u ./...
>
> 2. A script to be run manually (or via go generate? yikes!) before 
> running go get -u ./..., containing abominations like this:
>
> > go mod edit -replace github.com/foo/bar=$(go list -mod=mod -m 
> github.com/foo/bar@baz | sed -e 's/ /@/')
> > go mod edit -replace github.com/foo/bar1=$(go list -mod=mod -m 
> github.com/foo/bar1@baz | sed -e 's/ /@/')
> > ...etc...
> > go get -u ./...
>
> 3. Alternative abominations like this:
>
> > go mod edit -replace github.com/foo/bar=github.com/foo/bar $(curl -s 
> https://proxy.golang.org/github.com/foo/bar/@v/baz.info | jq -r .Version)
> > go mod edit -replace github.com/foo/bar1=github.com/foo/bar1 $(curl -s 
> https://proxy.golang.org/github.com/foo/bar1/@v/baz.info | jq -r .Version)
> > ...etc...
> > go get -u ./...
>
> I'm wondering: is there a better way? Should there be?
>
> Many thanks!
>
> Jim Minter
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/147a99cd-4c81-45e6-903a-a9813e891037n%40googlegroups.com.

Reply via email to