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

Re: [PATCH 1/3] submodule: make submodule.<name>.gitdir relative for worktrees

From
Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Date
Nov 14, 2026, 15:27 UTC
Message-ID
<CAF5D8-sJkCzL85boqNDnuU+wWthMSB37h5SJOny4hDUfe8y1rg@mail.gmail.com>
In-Reply-To
<f9adc6c85c4b098a0df8cf18783d1969a68fc048.1794484985.git.gitgitgadget@gmail.com>

On Thu, Nov 12, 2026 at 9:03 PM Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 48 quoted lines
>
> From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
>
> For a linked worktree, always keep `submodule.<name>.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 <yoichi.nakayama@gmail.com>
> ---
>  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
Previous: Yoichi NAKAYAMA via GitGitGadgetNext: Yoichi NAKAYAMA
Message 3 of 6 in “submodule: support worktree-specific configuration”
  1. 0/3 submodule: support worktree-specific configurationYoichi NAKAYAMA via GitGitGadget, Nov 12, 2026
  2. 1/3 submodule: make submodule.<name>.gitdir relative for worktreesYoichi NAKAYAMA via GitGitGadget, Nov 12, 2026
  3. Yoichi NAKAYAMANov 14, 2026
  4. Yoichi NAKAYAMANov 14, 2026
  5. 2/3 submodule: store settings in worktree config when enabledYoichi NAKAYAMA via GitGitGadget, Nov 12, 2026
  6. 3/3 submodule init: copy submodule.<name>.gitdir to config.worktreeYoichi NAKAYAMA via GitGitGadget, Nov 12, 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.