go get on forked github repo got "unexpected module path" error
Asked Answered
S

1

7

I'm currently working something on AWS Cloudformation which using this repo https://github.com/awslabs/goformation. Because I did some customise so I made a fork https://github.com/vrealzhou/goformation.

Now in my other project (using go module) I'm trying to using go get github.com/vrealzhou/[email protected] and I've got this error:

go: github.com/vrealzhou/[email protected]: parsing go.mod: unexpected module path "github.com/awslabs/goformation"
go: error loading module requirements

Does anyone know the reason and how to solve this problem? Thanks

Seiler answered 14/5, 2019 at 2:7 Comment(6)
guess you only change master branch, not tag v2.3.1?Humbuggery
You a github fork is a new package with new import path and 100% unrelated to the original. YOu must rewrite all import in your fork.Thanh
@Humbuggery My change was in add_features branch and tagged as v2.3.1. You can check my source.Seiler
@Thanh I did what you've said in master with tag v2.3.2 already but still got the similar error when I run go get github.com/vrealzhou/[email protected]Seiler
You must understand that you basically cannot "fork" (in the Github sense) a Go repo. What you can do is create a new package and everything in there must use the new package import path, starting from the go.mod and all imports. Probably you should not "customize" goformation but provide a wrapper.Thanh
You can use replace in your go.mod to do exactly what you're looking for - use a fork without updating imports or anything. I posted an answer with the updates needed for the go.mod.Webbing
W
12

You can use replace in your go.mod to use a fork instead of the upstream version. That way, you can make whatever modifications you need to the code without having to update the module path or import paths.

To be specific, in this case, you can do the following in your go.mod (I tested this by forking the repo, making a small change, and confirming it showed up):

require github.com/awslabs/goformation v1.4.1

replace github.com/awslabs/goformation => github.com/vrealzhou/goformation master

The first time you build or test, master will be replaced by the latest pseudo-version for your fork to make sure you get repeatable builds. The replace requires a specific version for the replacement.

Webbing answered 29/5, 2019 at 13:49 Comment(1)
I believe this is missing the module line at the top of the example. In this case, any module name will work as it is not publishedTestee

© 2022 - 2024 — McMap. All rights reserved.