On Sun, Nov 29, 2026 at 5:32 PM Junio C Hamano <gits…@pobox.com> wrote:
> > "Yoichi NAKAYAMA via GitGitGadget" <gitg…@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.
I understand that an issue remains if a path containing a symlink is already stored in `submodule.<name>.gitdir`. I will add a test and replace `strbuf_normalize_path(&submodule)` with `strbuf_realpath_forgiving(&submodule, submodule.buf, 0)`. It can convert submodule to an absolute path even if the submodule's gitdir and its parent directory ("modules") have not created yet.
> > +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.
I was assuming a case where the user has specified a custom path, rather than another worktree's submodule. However, the final sentence would be nonsensical if the value is for another worktree's submodule, and it is unnecessary even when a custom path is specified. I will remove that final sentence.
> > ... > > + 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?
Yes. I'll put _(). Thanks,
-- Yoichi NAKAYAMA