# Re: git init --separate-git-dir does not update symbolic .git links for submodules

2 messages from 2017-03-07 to 2017-03-07. Participants: Valery Tolstov, Stefan Beller.
Thread: https://gitlist.dev/t/45308

## Valery Tolstov, 2017-03-07 18:59

Subject: Re: git init --separate-git-dir does not update symbolic .git links for submodules
Message-ID: <1488913150.8812.0@smtp.yandex.ru>
URL: https://gitlist.dev/e/1488913150.8812.0%40smtp.yandex.ru

```
I think we can reuse code from module_clone that writes .git link.
Possibly this code fragment needs to be factored out from module_clone

Also, to fix all the links, we need to obtain the list of submodules
and then iterate over them. module_list command iterates
and prints the result to stdout. Maybe we can reuse this output.
Or create separate function that returns the list of submodules.

Can we call these functions from submodule--helper inside init command,
or run them thorugh internal command interface?

In my opinion, make submodule--helper fully responsible for link fixes
would be a good solution. Then we create two additional function, one
that fixes all submodules on the current level, and another that
fixes individual submodule.
Although it looks good, I'm not quite sure that it's really good.

So, maybe we can do link fixes like this:

    1. Start fixing from init command using submodule--helper, with
       subcommand that fixes all submodules on current level
    2. Each submodule processed with another subcommand/function in
       submodule--helper individually
    3. Repeat for current submodule recursively

Glad to see your advices.

Regards,
  Valery Tolstov




```

## Stefan Beller, 2017-03-07 19:59

Subject: Re: git init --separate-git-dir does not update symbolic .git links for submodules
Message-ID: <CAGZ79kY+1E-wg0-uzGJmE+haOE+1WCmg0Eux7rWGtkU_aBDQ9g@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kY%2B1E-wg0-uzGJmE%2BhaOE%2B1WCmg0Eux7rWGtkU_aBDQ9g%40mail.gmail.com
In-Reply-To: <1488913150.8812.0@smtp.yandex.ru>

```
On Tue, Mar 7, 2017 at 10:59 AM, Valery Tolstov <me@vtolstov.org> wrote:
> I think we can reuse code from module_clone that writes .git link.
> Possibly this code fragment needs to be factored out from module_clone

That fragment already exists, see dir.h:
connect_work_tree_and_git_dir(work_tree, git_dir);
Maybe another good microproject is to use that in module_clone.

>
> Also, to fix all the links, we need to obtain the list of submodules
> and then iterate over them.

Right, but a submodule may have a nested submodule.
So we need to fix each submodule from that list recursively,
i.e. not just the submodule itself, but any potential nested
submodule in that submodule, too.
(the listing doesn't list these nested submodules)

So we would call

    fix_gitlink(sub)
    {
        fix_locally(sub);

        // have a child process that calls
        // this function on any submodule inside sub.
    }

> module_list command iterates
> and prints the result to stdout. Maybe we can reuse this output.
> Or create separate function that returns the list of submodules.

yeah you can make use of module_list_compute to just produce
the list internally.

>
> Can we call these functions from submodule--helper inside init command,
> or run them thorugh internal command interface?

Both sounds fine, though calling internally is preferable for
performance reasons.

>
> In my opinion, make submodule--helper fully responsible for link fixes
> would be a good solution. Then we create two additional function, one
> that fixes all submodules on the current level, and another that
> fixes individual submodule.
> Although it looks good, I'm not quite sure that it's really good.

That sounds good to me.

So "git init --separate-git-dir" calls internally a new function
in the submodule--helper to

>
> So, maybe we can do link fixes like this:
>
>    1. Start fixing from init command using submodule--helper, with
>       subcommand that fixes all submodules on current level

for this step we do not change the repository we are in, so there
is no need to call a new process, but we rather want to
call it internally.

>    2. Each submodule processed with another subcommand/function in
>       submodule--helper individually

sounds good.

>    3. Repeat for current submodule recursively

and this recursive action needs to have its own process in the submodule,
e.g. "git submodule--helper --recursive fix-git-links"

>
> Glad to see your advices.
>
> Regards,
>  Valery Tolstov

Regards,
Stefan

```
