From: Yoichi NAKAYAMA Date: Sat, 14 Nov 2026 15:27:36 GMT Subject: Re: [PATCH 1/3] submodule: make submodule..gitdir relative for worktrees Message-ID: In-Reply-To: On Thu, Nov 12, 2026 at 9:03 PM Yoichi NAKAYAMA via GitGitGadget wrote: > > From: Yoichi NAKAYAMA > > For a linked worktree, always keep `submodule..gitdir` relative > to ensure it continues to work when the worktree is moved along with > the main worktree. (This benefit also requires > worktree.useRelativePaths to be set to true.) > > Signed-off-by: Yoichi NAKAYAMA > --- > builtin/submodule--helper.c | 68 +++++++++++++--------- > t/t7425-submodule-gitdir-path-extension.sh | 19 ++++++ > 2 files changed, 61 insertions(+), 26 deletions(-) > > diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c > index 461b682d0d..56d7720e93 100644 > --- a/builtin/submodule--helper.c > +++ b/builtin/submodule--helper.c > @@ -37,6 +37,7 @@ > #include "wildmatch.h" > #include "strbuf.h" > #include "url.h" > +#include "worktree.h" > > #define OPT_QUIET (1 << 0) > #define OPT_CACHED (1 << 1) > @@ -507,50 +508,60 @@ static int validate_and_set_submodule_gitdir(struct strbuf *gitdir_path, > > static void create_default_gitdir_config(const char *submodule_name) > { > + struct worktree *wt = get_current_worktree(the_repository); > + const char *modules_dir; > + struct strbuf tmp = STRBUF_INIT; > struct strbuf gitdir_path = STRBUF_INIT; > struct git_hash_ctx ctx; > char hex_name_hash[GIT_MAX_HEXSZ + 1], header[128]; > unsigned char raw_name_hash[GIT_MAX_RAWSZ]; > int header_len; > > - /* Case 1: try the plain module name */ > - repo_git_path_append(the_repository, &gitdir_path, "modules/%s", submodule_name); > - if (!validate_and_set_submodule_gitdir(&gitdir_path, submodule_name)) { > - strbuf_release(&gitdir_path); > - return; > + modules_dir = worktree_git_path(wt, "modules/"); > + if (is_absolute_path(modules_dir)) { > + modules_dir = relative_path(modules_dir, wt->path, &tmp); > } I noticed that worktree_git_path() returns a pointer to a static buffer managed by get_pathname(). I'll copy the result into tmp immediately, before calling other functions that might overwrite the buffer: modules_dir = worktree_git_path(wt, "modules/"); if (is_absolute_path(modules_dir)) relative_path(modules_dir, wt->path, &tmp); else strbuf_addstr(&tmp, modules_dir); modules_dir = tmp.buf; Thanks, -- Yoichi NAKAYAMA