12

As described in this Question

Is it possible for a git submodule to be made of several other git submodules, and the super git repo to fetch the contents for each submodule?

The author assumed a git submodule hierarchy like this:

  • repo1
    • submodule xyz1
    • submodule xyz2
  • repo2
    • submodule repo1

This question is about the possibility of nesting a submodule within a submodule:

  • repo1
    • submodule a
      • submodule ab
      • submodule ac

Real example of a .gitmodules should look like this:

[submodule "Source/V8"]
    path = Source/V8
    url = https://chromium.googlesource.com/v8/v8.git
[submodule "Source/V8/build/gyp"]
    path = Source/V8/build/gyp
    url =  https://chromium.googlesource.com/external/gyp
[submodule "Source/V8/third_party/cygwin"]
    path = Source/V8/third_party/cygwin
    url = https://chromium.googlesource.com/chromium/deps/cygwin
[submodule "Source/V8/third_party/python_26"]
    path = Source/V8/third_party/python_26
    url = https://chromium.googlesource.com/chromium/deps/python_26
[submodule "Source/V8/third_party/icu"]
    path = Source/V8/third_party/icu
    url = https://chromium.googlesource.com/chromium/deps/icu52
[submodule "Source/V8/testing/gtest"]
    path = Source/V8/testing/gtest
    url = https://chromium.googlesource.com/chromium/testing/gtest
[submodule "Source/V8/testing/gmock"]
    path = Source/V8/testing/gmock
    url = https://chromium.googlesource.com/chromium/testing/gtest

Note that the path of the submodules are nested:

  • Source/V8
    • Source/V8/build/gyp
    • Source/V8/third_party/cygwin

I tried the following example with no success:

 git submodule add https://chromium.googlesource.com/v8/v8.git   
 Source/V8
 git submodule add https://chromium.googlesource.com/external/gyp 
 Source/V8/build/gyp 

results in:

 The following path is ignored by one of your .gitignore files:
 Source/V8/build/gyp
 Use -f if you really want to add it.

using git submodule add -f results in:

Cloning into 'Source/V8/build/gyp'...
remote: Sending approximately 10.28 MiB ...
remote: Total 16486 (delta 10444), reused 16486 (delta 10444)
Receiving objects: 100% (16486/16486), 10.28 MiB | 2.07 MiB/s, done.
Resolving deltas: 100% (10452/10452), done.
Checking connectivity... done.
fatal: Pathspec 'Source/V8/build/gyp' is in submodule 'Source/V8'
Failed to add submodule 'Source/V8/build/gyp'

Please let me now if this case is possible to achieve.

Update: Note this question is about creating a submodule structure, not initializing it.

Community
  • 1
  • 1
chrisber
  • 700
  • 1
  • 11
  • 27

2 Answers2

-1

Yes, nested submodules is possible although not necessarily advisable. If you really want to create nested submodule, you have to use the following command:

git submodule update --init --recursive

A similar question had actually been asked before. You should have a look here

Community
  • 1
  • 1
iclman
  • 1,070
  • 8
  • 18
  • 3
    Sorry this is the wrong answer, please compare the two questions carefully, my question is about creating a submodule structure, not initializing it. – chrisber Jan 24 '15 at 09:18
  • 1
    @Karl2011, have you tried to do git submodule add https://chromium.googlesource.com/v8/v8.git Source/V8. Then go into Source/V8 directory. In that directory, you should then git submodule add https://chromium.googlesource.com/external/gyp external/gyp. The directory external/gyp would then be a submodule inside Source/V8. – iclman Jan 24 '15 at 21:55
  • 2
    Yes, I tried it but this adds a submodule to the v8 repository and not to the root repository. – chrisber Jan 24 '15 at 22:30
  • 1
    Source/V8 is already a submodule of the root repository. You can therefore not add Source/V8/external/gyp as a submodule of the root repository. You can only add it as a submodule of the Source/V8. Another option is to add external/gyp at the same level as Source/V8 and then create a symbolic link from Source/V8/external/gyp to External/gyp. In that case External/gyp will be created as a submodule of the root repo. – iclman Jan 24 '15 at 22:43
-1

Submodules should be added to a repository, not to a submodule.
Then, after they are tracked in the top repository, the top repository may be used as a submodule in another project , resulting in a nested submodules structure.
In your example, you should add gyp as a submodule to the V8 project. If you cannot affect the top project, then yous should ask yourself what is the meaning of adding a submodule to this project?
When the desired structure is built, you may use the command that @iclman suggested in order to bring all submodules in:
git submodule update --init --recursive

mikeraf
  • 61
  • 6
  • Welcome to SO, we appreciate your input! Could you please edit your question and make it self-contained, by explaining what iclman said? See also https://stackoverflow.com/help/how-to-answer – B--rian Aug 22 '19 at 07:39