git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Submodules & worktree

From
Philippe Blain <levraiphilippeblain@gmail.com>
Date
Jan 28, 2020, 04:01 UTC
Message-ID
<EE184A05-60BD-4939-93E6-C156A0DB3DF8@gmail.com>
In-Reply-To
<CAKQS2dqx9Nux11ot7a-Wxd2qpcdAAWw-e7Li+X3bw7TxJS=Kyw@mail.gmail.com>
Hi Ole,
Show 9 quoted lines
> Le 1 févr. 2019 à 09:00, Ole Pinto <olepinto@gmail.com> a écrit :
> 
> Adding a worktree from a working copy with submodules doesn't work.
> 
> In the config file I have
>   [submodule]
>       recurse = true
> 
> It that's not present, I don't find the problem.

I also stumbled upon this bug and fixed it in 4782cf2ab6 (worktree: teach "add" to ignore submodule.recurse config, 2019-10-27), which was merged in 05fc6471e3 (Merge branch 'pb/no-recursive-reset-hard-in-worktree-add', 2019-12-01) and made it to Git 2.25. `git worktree add` now works correctly in a project with submodules, and cd-ing to the new worktree directory and issuing `git submodule update` inits and clones the submodule(s) to .git/worktrees/<worktree-name>/modules/<submodule-name>, as it should.

I must warn you however that I discovered another bug that can happen with the submodule.recurse config when using worktrees with projects that have submodules. In short, issuing `git checkout` (or `git reset` or `git read-tree`) in one of the worktrees will leave the .git file in the submodule incorrectly pointing to the repository of the submodule in the main worktree, i.e. .git/modules/<submodule-name> instead of .git/worktrees/<worktree-name>/modules/<submodule-name>. I also fixed this bug [1], my patch series for this is currently in next. 
[1] https://github.com/gitgitgadget/git/pull/523
Show 16 quoted lines
> # Problem 2 (submodule status seems not to detect some cases)
> 
> $ pwd
> /tmp/main_repo
> 
> $ git submodule status
> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod (heads/master)
> 
> $ rm submod/file.txt submod/.git
> 
> $ git submodule status
> ebc9325f7b19164c9bdfd05263481ded66d7bd7d submod
> 
> So, I have a plain, empty directory where the submodule should be. Not
> having any 'first char', I'd expect it to be checked out and up to
> date. Is this expected?

This is indeed not expected, and used to work correctly (the hash should be prefixed with a ‘-‘) in Git 2.12. This bevaviour regressed when `git submodule status` was ported to C in a9f8a37584 (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06). Another user reported this regression to the list recently and a patch series is in the works to fix it [2].

[2] https://lore.kernel.org/git/xmqqv9owbw5o.fsf@gitster-ct.c.googlers.com/

Cheers, Philippe.

Previous: Mateusz LoskotNext: Philippe Blain
Message 3 of 5 in “Fwd: Submodules & worktree”
  1. Ole PintoFeb 1, 2019
  2. Mateusz LoskotFeb 1, 2019
  3. Philippe BlainJan 28, 2020
  4. Philippe BlainJan 28, 2020
  5. Philippe BlainJan 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.