2

We have a project which needs another external project (which I can't modify) as a submodule. That submodule again has submodules. However one of those submodules isn't necessary and the server it's on is unreliable.

Is there any way to only clone a part of the submodules of the submodule?

CodeMonkey
  • 4,067
  • 1
  • 31
  • 43
  • 1
    try cloning the superproject, then run git submodule init and git submodule update only in the submodules you need. Remember that the super submodule will try to get data from all of its submodules – Daemon Painter Nov 30 '20 at 14:34
  • @DaemonPainter thank you, but that solution doesn't scale, since there are many submodules here, and submodules of submodules. So this would take ages for every user. – CodeMonkey Nov 30 '20 at 14:38
  • 1
    since you have access to the external submodules, why not import only those, removing dependency from the external project? In the end, you could recreate a version of the external project with links to those submodules you need – Daemon Painter Nov 30 '20 at 14:40
  • https://stackoverflow.com/a/52185169/7976758, https://stackoverflow.com/search?q=%5Bgit-submodules%5D+recursive+exclude – phd Nov 30 '20 at 14:49
  • @phd Correct me if I'm wrong, these seem to exclude submodules on the first level if I understand correctly. But I want to exclude a single submodule of a submodule. – CodeMonkey Nov 30 '20 at 15:17
  • @DaemonPainter we might go that route if there's no option for this in git. – CodeMonkey Nov 30 '20 at 15:27
  • It excludes submodules from updating on the previous level. Other then that you don't have many options — you're trying to do a non-standard thing. – phd Nov 30 '20 at 15:36

1 Answers1

0

Your situation is one where your repository is a Superproject importing several submodules. Some of which are Superprojects themselves.

You have complete control over your superproject, but cannot modify the external resources you import. However, you have complete access to all the submodules and nested submodules (otherwise you wouldn't be able to clone).

It appears that some of the resources you import from one of the Super-submodules are not needed in your project, and you'd like to get rid of them.

Recreate the external resource

Add as submodules only those submodules you actually need, instead of the Super-submodule that is creating fuzz. You'll have to modify the architecture of the project a bit to make the necessary modifications, but you'll manage in the end.

Exclude some submodules from cloning

As pointed out by phd, you may exclude some submodules from cloning. Some comments point out that you might even be able to prevent a submodule submodule from being cloned:

git -c submodule."third-party/submodule".update=none submodule update --init --recursive
                  ^ a submodule of a submodule
                  
Daemon Painter
  • 3,208
  • 3
  • 29
  • 44