I'm tinkering with a Go project ( let's call it foobar ), which has a dependency upon yet another Go project ( let's call it snafu ) in the same organisation.
For the moment, I've got a fork of snafu in my own org - david-hay - and wanted to update go.mod in the foobar project to leverage it.
I knew I had to update go.mod either manually or use go mod edit --replace source=target but couldn't get past the exception: -
go: -replace=github.com/org/snafu=github.com/david-hay/snafu: unversioned new path must be local directory
It turned out, as ever, that I was holding it wrong ...
I needed to explicitly provide a "version" - in this context, that was a branch e.g. main at which to point the target during go mod edit --replace like this: -
go mod edit --replace github.com/org/snafu=github.com/david-hay/snafu@main
In other words, the right-hand side of the --replace directive needed to include four things: -
- domain e.g. github.com
- organization e.g. david-hay
- project/repo e.g. snafu
- branch e.g. main
like this: -
...
replace github.com/org/snafu => github.com/david-hay/snafu main
When I then ran go mod tidy, this went off to GitHub and pulled down the latest release from that branch in my fork: -
go: downloading github.com/david-hay/snafu v1.11.39-0.20230116121922-46267d910e38
and updated go.mod with: -
replace github.com/org/snafu => github.com/david-hay/snafu v1.11.39-0.20230116121922-46267d910e38
In other words, it replaced the branch with the release ... which is nice
With thanks to this: -
Pointing to a fork of a Go module