All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Ratiu <adrian.ratiu@collabora.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Andreas Wendleder <gonsolo@gmail.com>,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	Patrick Steinhardt <ps@pks.im>
Subject: Re: [PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir
Date: Thu, 19 Nov 2026 14:19:16 +0200	[thread overview]
Message-ID: <87y0aphv3v.fsf@collabora.com> (raw)
In-Reply-To: <xmqqv75t534o.fsf@gitster.g>

On Wed, 18 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:
>> @@ -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.

>
> 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!

      reply	other threads:[~2026-11-19 12:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:51 submodule: linked-worktree submodule hits BUG() in validate_submodule_legacy_git_dir() Andreas Wendleder
2026-11-17 17:45 ` Adrian Ratiu
2026-11-18 16:32 ` [PATCH 0/3] submodule: support linked worktrees in recursive checkout Adrian Ratiu
2026-11-18 16:32   ` [PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir Adrian Ratiu
2026-11-18 19:15     ` Junio C Hamano
2026-11-18 19:33       ` Adrian Ratiu
2026-11-18 16:32   ` [PATCH 2/3] submodule: only suggest submodulePathConfig when it is disabled Adrian Ratiu
2026-11-18 19:28     ` Junio C Hamano
2026-11-19 11:46       ` Adrian Ratiu
2026-11-19 22:14         ` Junio C Hamano
2026-11-18 16:32   ` [PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir Adrian Ratiu
2026-11-18 19:52     ` Junio C Hamano
2026-11-19 12:19       ` Adrian Ratiu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y0aphv3v.fsf@collabora.com \
    --to=adrian.ratiu@collabora.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=gonsolo@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.