Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: option to initialize go mod from git submodules #47824

Open
mcandre opened this issue Aug 19, 2021 · 2 comments
Open

cmd/go: option to initialize go mod from git submodules #47824

mcandre opened this issue Aug 19, 2021 · 2 comments

Comments

@mcandre
Copy link

@mcandre mcandre commented Aug 19, 2021

Hi,

I have historically used git submodules as the most reliable way to manage library dependencies in my Go projects. I would very much like to migrate to modern Go modules. However, the go mod init system does not appear to support generating go.mod configurations from git submodules.

When I try to do this, I either get NO modules in the resulting go.mod file, or else I get the latest versions of everything, which of course breaks my application. Please include automation for migrating vendor/ directories from git submodules to go.mod.

Furthermore, when I try to explicitly copy the exact same git refs for the dependency versions, then go mod operations corrupt these. go mod checks out a completely different version of the dependency tree than I have in the original vendor/ with git submodules.

If someone can help me to reliably migrate the exact same dependency tree to go mod, then I would be grateful.

Example:

https://github.com/mcandre/octane/tree/61e9374d9695f2b3f1489741396f4f3082f3fd74

@mknyszek mknyszek changed the title Option to initialize go mod from git submodules cmd/go: option to initialize go mod from git submodules Aug 19, 2021
@mknyszek mknyszek added this to the Backlog milestone Aug 19, 2021
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Aug 19, 2021

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Aug 20, 2021

Could you say more about how you're using submodules? Concepts in Go modules and Git submodules don't map directly to each other, so it's not clear to me how this would work or whether it would be feasible.

It sounds like you have submodules checked out into the vendor directory, presumably at locations that correspond to repository root paths. If that's the case, then git submodule status would show something like this for each repo:

012345abcdef vendor/example.com/repo

It's probably feasible for go mod init to list directories inside vendor containing .go files, find what submodule they belong to, then build a go.mod based on that. Does that sound about right?

We're probably not going to be able to get to this soon; I don't think many people are in this situation. In the mean time, you can simulate the result by using go get to pull in each dependency.

go get -d example.com/repo@012345abcdef

@jayconrod jayconrod removed this from the Backlog milestone Aug 20, 2021
@jayconrod jayconrod added this to the Unplanned milestone Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants