Apparently, adding a subtree of a repository that has submodules will break git submodule init
. Here is a script which reproduces the problem:
#
From what I can tell reading the docs and source code... Git subtree is completely separate from Git submodules and will not actively manage any submodules that may be contained within the subtree project itself.
As you found out, .gitsubmodules
, which is critical to the function of git submodule init
, needs to be maintained in the root of the "main" repository (for lack of a better term).
Upon further consideration, it is clear what the problem is: the subtree mechanism has added subtree's submodule reference to submod to the tree, but the .gitmodules metadata remains in subtree/.gitmodules, not the top-level .gitmodules, which means that git submodule init fails. If we copy the contents of subtree/.gitmodules to .gitmodules, adjusting all the paths accordingly, that solves the problem...
I strongly recommend not mixing these features.