1

It's possible with git submodules to checkout multiple repositories as submodules into respective paths, e.g.:

% git submodule add git@.../repo1.git ./here/is/1
% git submodule add git@.../repo2.git ./here/is/2

But what if I need to checkout the contents of repo1 and repo2 both into a single path, ./here/is/3?

Basically I have a metric shit-ton of submodule repos I need to all be checked out into a very rigid directory hierarchy on the client side when the user does git clone --recursive ...

I want the contents of all submodules to be checked out into ./somepath. Can it be done?

One thing I considered was using symlinks, but that feels wrong.

EDIT:

I want the contents of 1 and 2 in the above to be placed in the same target directory on the client. I can do this by having the user manually run a script after cloning (it is not possible to have git track a single file), but it seems like there should be a cleaner way to do this -- manually creating a symlink for each submodule is a lot of work, and it seems like the submodule abstraction should be able to handle this.

Maybe my question is a dupe-in-disguise?

Community
  • 1
  • 1

1 Answers1

1

One way would be to create another parent repo, with the submodules declared directly in it:

newParentRepo/
  1/
  2/
  3/
  ...

That parent repo could be cloned --recursive in ./somepath, and the submodules would be directly under ./somepath (in their respective root directories 1/, 2/, ...).

You would need to synchronize the SHA1 of the submodules as recorded by the first parent repo into the second parent repo, in order for said second repo to record the right list of submodules SHA1.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The "in their respective root directories" part is a problem. I need all the junk in the submodules to be moved (or linked) to arbitrary places on the client side after `git clone`. Clarifying my question to reflect this. –  Feb 26 '13 at 15:52
  • @g33kz0r I confirm a submodule is *always* cloned in its own directory, never in the directory of another submodule. Each submodule *must* be in their own directory. Any other organization is a *deployment* issue (copying / symlinks), but it has nothing to do with git anymore. – VonC Feb 26 '13 at 15:57
  • Ok. Looks like I have to create the symlinks *a priori*, since Git doesn't have a post-clone hook. –  Feb 26 '13 at 16:00
  • @g33kz0r Or you could create them through a script that you would declare as a post checkout hook. – VonC Feb 26 '13 at 16:07
  • Right, but hooks only run on my local copy. Anyone else who checks out the code won't benefit from the hook, as they are neither version controlled nor shared between repositories (github). –  Feb 26 '13 at 16:57
  • @g33kz0r I agree: http://stackoverflow.com/a/5165299/6309 or http://stackoverflow.com/a/3703207/6309 – VonC Feb 26 '13 at 17:57