# After-the-fact submodule detection or creation

3 messages from 2007-12-07 to 2007-12-07. Participants: Michael Poole, Alex Riesen.
Thread: https://gitlist.dev/t/11171

## Michael Poole, 2007-12-07 03:01

Subject: After-the-fact submodule detection or creation
Message-ID: <87ir3bp5sf.fsf@graviton.dyn.troilus.org>
URL: https://gitlist.dev/e/87ir3bp5sf.fsf%40graviton.dyn.troilus.org

```
I have a project where most branches have one subdirectory for the
core program and other subdirectories for support scripts, programs
and libraries.  The supporting subdirectories vary from branch to
branch.  However, some branches contain just the core program, with no
subdirectories.  Starting from scratch, I would say the core program
should be a submodule, but historically it was not populated as one.

Is there a way to easily create such a pseudo-submodule branch in git,
or are real submodules strongly preferred for this kind of scenario?

(The added twist: I ran into this while importing a Subversion
repository.  git-svn identified two trees of history in the repository
-- one history containing the core plus support trees, one history
containing just the core program.  Since the trees do have the same
contents, only the commits are duplicated, but that is not quite
ideal.

It seems like using the current submodule code would mean that this
kind of import would need two passes over the foreign repository,
rather than one if the branch could be created after the parent tree
is initially imported.  I can live with that -- it is a rather unusual
case -- but maybe there is a better way.)

Michael Poole

```

## Alex Riesen, 2007-12-07 07:37

Subject: Re: After-the-fact submodule detection or creation
Message-ID: <20071207073728.GA2847@steel.home>
URL: https://gitlist.dev/e/20071207073728.GA2847%40steel.home
In-Reply-To: <87ir3bp5sf.fsf@graviton.dyn.troilus.org>

```
Michael Poole, Fri, Dec 07, 2007 04:01:04 +0100:
> It seems like using the current submodule code would mean that this
> kind of import would need two passes over the foreign repository,
> rather than one if the branch could be created after the parent tree
> is initially imported.  I can live with that -- it is a rather unusual
> case -- but maybe there is a better way.)

Import the core module in a branch all by itself, and merge it in
every support branch?


    Supp1: o-o-o-----o-o-o-o-o-o-o
		    /
    Core:  o-o-o-o-o
		    \
    Supp2: o-o-------o-o-o-o

```

## Michael Poole, 2007-12-07 21:35

Subject: Re: After-the-fact submodule detection or creation
Message-ID: <87abomp4r4.fsf@graviton.dyn.troilus.org>
URL: https://gitlist.dev/e/87abomp4r4.fsf%40graviton.dyn.troilus.org
In-Reply-To: <20071207073728.GA2847@steel.home>

```
Alex Riesen writes:

> Michael Poole, Fri, Dec 07, 2007 04:01:04 +0100:
>> It seems like using the current submodule code would mean that this
>> kind of import would need two passes over the foreign repository,
>> rather than one if the branch could be created after the parent tree
>> is initially imported.  I can live with that -- it is a rather unusual
>> case -- but maybe there is a better way.)
>
> Import the core module in a branch all by itself, and merge it in
> every support branch?
>
>
>     Supp1: o-o-o-----o-o-o-o-o-o-o
> 		    /
>     Core:  o-o-o-o-o
> 		    \
>     Supp2: o-o-------o-o-o-o

Yes, that's the obvious way to do it with submodules.  Teaching
git-svn to use that is the hard part.

Since the core code was first branched independently at r734 in the
existing repository, the import (either automated or manual) would
need to go through once to identify what subdirectories are actually
submodules in git terminology, and make a second pass to actually
perform the imports.  If the submodule creation could happen after the
fact, it would only need one pass.

Maybe the right question to ask is whether having a partial-tree
branch can be reasonably handled by git (in particular, detecting a
rename of the core subtree to the top-level tree in the new branch's
first commit).  If git understand that operation, then what I would
like to do would be reasonably straightforward.  If it does not make
sense, then I'll think about how to teach git-svn that certain
subdirectories should be promoted to submodules.

Michael Poole

```
