From: Junio C Hamano <gitster@pobox.com>
To: "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Subject: Re: [PATCH v3 4/4] submodule init: copy submodule.<name>.gitdir to config.worktree
Date: Sun, 29 Nov 2026 00:32:56 -0800 [thread overview]
Message-ID: <xmqqjylwnikn.fsf@gitster.g> (raw)
In-Reply-To: <3e2c1612988ea1bc74b94a2cfc17e24dfd41ca3e.1795903557.git.gitgitgadget@gmail.com> (Yoichi NAKAYAMA via GitGitGadget's message of "Sat, 28 Nov 2026 22:05:57 +0000")
"Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +static bool submodule_git_dir_matches_current_worktree(const char *gitdir)
> +{
> + struct strbuf tmp = STRBUF_INIT;
> + struct strbuf submodule = STRBUF_INIT;
> + char *super;
> + bool matches;
> +
> + if (is_absolute_path(gitdir))
> + strbuf_addstr(&submodule, gitdir);
> + else if (!repo_worktree_path_append(the_repository, &submodule,
> + "%s", gitdir))
> + return false;
> +
> + if (strbuf_normalize_path(&submodule)) {
> + strbuf_release(&submodule);
> + return false;
> + }
> +
> + super = real_pathdup(repo_get_git_dir(the_repository), 1);
> + matches = starts_with(relative_path(submodule.buf, super, &tmp),
> + "modules/");
Isn't there still a symlink asymmetry here?
While 'super' now resolves symlinks via real_pathdup(), 'submodule' only
goes through strbuf_normalize_path(), which performs purely lexical
normalization without calling lstat() or readlink().
Suppose a repository 'repo' has a symlink 'repo-link' pointing to it,
and an older Git (before [PATCH 2/4]) wrote an absolute path through the
symlink into the repository config, such as
"/path/to/repo-link/.git/modules/sub1_custom" (or a value containing a
symlinked parent directory like /tmp or /var).
When the user later enables extensions.worktreeConfig and runs "git
submodule init" in 'repo':
1. strbuf_normalize_path() leaves the symlink component in 'submodule.buf'
unresolved, so it stays "/path/to/repo-link/.git/modules/sub1_custom".
2. real_pathdup() resolves 'super' to "/path/to/repo/.git".
3. relative_path() compares the two strings byte-by-byte, diverges at
'repo-link' vs 'repo', and returns "../../repo-link/.git/modules/sub1_custom"
instead of "modules/sub1_custom".
4. submodule_git_dir_matches_current_worktree() then returns false,
emitting the mismatch warning and overwriting the custom setting in
config.worktree with ".git/modules/sub1".
The new test in t7425 uses "pwd -P", which may hide this case.
Using strbuf_realpath_forgiving(&submodule, submodule.buf, 0) instead of
(or before) strbuf_normalize_path(&submodule) keeps both sides
canonicalized even when the final submodule gitdir directory does not
exist yet, avoids collapsing "<symlink>/.." lexically before resolving
the symlink, and lets invalid paths return false cleanly.
> +static const char submodule_mismatch_warning[] = N_(
> +"config '%s' exists but was not copied to the worktree config because "
> +"it does not point to a gitdir for the current worktree. If you want "
> +"to keep using this setting, copy it to the worktree config."
> +);
The sentence "If you want to..." feels a bit odd, doesn't it? "git
submodule init" just wrote a fallback setting into config.worktree and
sharing another worktree's gitdir is usually not what you want to do.
Saying "If you want to use this setting here, set it in the worktree
config.' or dropping that sentence altogether may make the message less
confusing. I dunno.
> ...
> + if (!matches ||
> + validate_submodule_git_dir(tmp, submodule_name)) {
> + if (!matches)
> + warning(submodule_mismatch_warning, key);
You'd need _() around submodule_mismatch_warning don't you?
prev parent reply other threads:[~2026-11-29 8:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 12:03 [PATCH 0/3] submodule: support worktree-specific configuration Yoichi NAKAYAMA via GitGitGadget
2026-11-12 12:03 ` [PATCH 1/3] submodule: make submodule.<name>.gitdir relative for worktrees Yoichi NAKAYAMA via GitGitGadget
2026-11-14 15:27 ` Yoichi NAKAYAMA
2026-11-14 15:47 ` Yoichi NAKAYAMA
2026-11-12 12:03 ` [PATCH 2/3] submodule: store settings in worktree config when enabled Yoichi NAKAYAMA via GitGitGadget
2026-11-12 12:03 ` [PATCH 3/3] submodule init: copy submodule.<name>.gitdir to config.worktree Yoichi NAKAYAMA via GitGitGadget
2026-11-21 15:10 ` [PATCH v2 0/3] submodule: support worktree-specific configuration Yoichi NAKAYAMA via GitGitGadget
2026-11-21 15:10 ` [PATCH v2 1/3] submodule: make submodule.<name>.gitdir relative for worktrees Yoichi NAKAYAMA via GitGitGadget
2026-11-24 19:44 ` Junio C Hamano
2026-11-27 5:04 ` Yoichi NAKAYAMA
2026-11-27 5:23 ` Junio C Hamano
2026-11-27 6:15 ` Yoichi NAKAYAMA
2026-11-21 15:10 ` [PATCH v2 2/3] submodule: store settings in worktree config when enabled Yoichi NAKAYAMA via GitGitGadget
2026-11-24 20:14 ` Junio C Hamano
2026-11-27 12:35 ` Yoichi NAKAYAMA
2026-11-21 15:10 ` [PATCH v2 3/3] submodule init: copy submodule.<name>.gitdir to config.worktree Yoichi NAKAYAMA via GitGitGadget
2026-11-24 20:44 ` Junio C Hamano
2026-11-28 0:14 ` Yoichi NAKAYAMA
2026-11-28 22:05 ` [PATCH v3 0/4] submodule: support worktree-specific configuration Yoichi NAKAYAMA via GitGitGadget
2026-11-28 22:05 ` [PATCH v3 1/4] submodule init: make submodule.<name>.gitdir relative for worktrees Yoichi NAKAYAMA via GitGitGadget
2026-11-28 22:05 ` [PATCH v3 2/4] submodule init: resolve symlinks in submodule.<name>.gitdir Yoichi NAKAYAMA via GitGitGadget
2026-11-28 22:05 ` [PATCH v3 3/4] submodule: store settings in worktree config when enabled Yoichi NAKAYAMA via GitGitGadget
2026-11-28 22:05 ` [PATCH v3 4/4] submodule init: copy submodule.<name>.gitdir to config.worktree Yoichi NAKAYAMA via GitGitGadget
2026-11-29 8:32 ` Junio C Hamano [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=xmqqjylwnikn.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=yoichi.nakayama@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox