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

Re: [PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir

From
Adrian Ratiu <adrian.ratiu@collabora.com>
Date
Nov 19, 2026, 12:19 UTC
Message-ID
<87y0aphv3v.fsf@collabora.com>
In-Reply-To
<xmqqv75t534o.fsf@gitster.g>
On Wed, 18 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
>> @@ -2191,7 +2232,13 @@ int submodule_move_head(const char *path, const char *super_prefix,
>>  			submodule_reset_index(path, super_prefix);
>>  		}
>>  
>> -		if (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {
>> +		/*
>> +		 * Do not reconnect a linked worktree to the submodule's
>> +		 * main git dir: that would take over the git dir of another
>> +		 * working tree.
>> +		 */
>> +		if (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE) &&
>> +		    !is_worktree) {
>
> If a linked-worktree submodule 'sub' contains a nested submodule
> 'inner' whose .git is a directory, submodule_uses_gitfile("sub")
> would have returned 0 (because the check is recursive), we ran
> absorb_git_dir_into_superproject() (which is also recursive so it
> would cause .git in 'inner' to be absorbed), and is_worktree is
> still 0 at this point, which means if() condition here is satisfied
> (if forced) and we will enter this block.  Would it cause an issue?

Yes, good catch. I reproduced it with a "sub" linked worktree and a "sub/inner/.git" directory, a recursive checkout absorbs the "inner" and then rewrites sub/.git to point to "$GIT_DIR/modules/sub" which does not exist:

  fatal: gitfile does not point to a valid repository: .git
  error: Submodule 'sub' could not be updated.

It's basically the same breakage this patch is meant to fix, just reached through the absorb path.

Show 16 quoted lines
>
> I am wondering if the check for is_worktree should be moved outside
> the else clause, i.e. making the overall flow look more like
>
>         if (old_head) {
>                 if (!submodule_uses_gitfile(path))
>                         absorb_git_dir_into_superproject(path, super_prefix);
>
>                 /*
>                  * Now path/.git is guaranteed to be a gitfile; 
>                  * validate and detect worktrees.
>                  */
>                 ...
>                 is_worktree = validate_submodule_gitfile_dir(git_dir, sub->name);
>                 ...
>         }

Yes, that fixes it, the sub/.git is left alone and the submodule is checked-out at the correct commit. The validation also runs after an absorb, but absorb puts the gitdir where submodule_name_to_gitdir() says it should be, so the check always passes.

> Or am I grossly misreading the code flow?
You understood it perfectly. :) I'll do this in v2 as well.
Many thanks!
Previous: Junio C Hamano
Message 13 of 13 in “submodule: linked-worktree submodule hits BUG() in validate_submodule_legacy_git_dir()”
  1. Andreas WendlederNov 16, 2026
  2. Adrian RatiuNov 17, 2026
  3. 0/3 submodule: support linked worktrees in recursive checkoutAdrian Ratiu, Nov 18, 2026
  4. 1/3 submodule: return an error instead of BUG() for an unexpected git dirAdrian Ratiu, Nov 18, 2026
  5. Junio C HamanoNov 18, 2026
  6. Adrian RatiuNov 18, 2026
  7. 2/3 submodule: only suggest submodulePathConfig when it is disabledAdrian Ratiu, Nov 18, 2026
  8. Junio C HamanoNov 18, 2026
  9. Adrian RatiuNov 19, 2026
  10. Junio C HamanoNov 19, 2026
  11. 3/3 submodule: accept a linked worktree as the submodule's git dirAdrian Ratiu, Nov 18, 2026
  12. Junio C HamanoNov 18, 2026
  13. Adrian RatiuNov 19, 2026

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.