Can I import a package from a git submodule?

996 views
Skip to first unread message

cpu...@gmail.com

unread,
Mar 31, 2021, 3:46:10 PM3/31/21
to golang-nuts
Consider this layout:

  • Repo A contains module foo
  • Repo B contains module bar (of course ;)
  • Repo B is added as submodule to repo A at /baz

I was expecting that I can 

import "foo/baz/bar"

in repo A, but that leads to error ("no required module provides package...").

Shouldn't this work as the import path is a perfectly valid import path inside module foo?

Cheers,
Andi

Axel Wagner

unread,
Mar 31, 2021, 4:46:22 PM3/31/21
to cpu...@gmail.com, golang-nuts
AIUI, if you nest modules (that is, a subdirectory of a module containing a directory with its own `go.mod`), the "inner" module is not considered part of the "outer" module. In particular, it would also not be included in the module zip (which is the primary way modules are distributed - *not* as repositories).

So, AIUI, `foo/baz/bar` is technically a valid import path, but it's not "inside" module `foo`, so to speak.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1f2bab6e-47cf-4f80-9a66-3a8bad2869ban%40googlegroups.com.

Marcin Romaszewicz

unread,
Mar 31, 2021, 5:17:30 PM3/31/21
to Axel Wagner, cpu...@gmail.com, golang-nuts
It's really annoying to deal with when you have private repositories, but try to simply `import RepoB/bar` from ModuleA, and don't bother with the submodule stuff. Module SHAs will replicate submodule functionality in a way that's more compatible with the language.

Reply all
Reply to author
Forward
0 new messages