Git development
 help / color / mirror / Atom feed
From: "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>,
	Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Subject: [PATCH v4 0/4] submodule: support worktree-specific configuration
Date: Wed, 02 Dec 2026 21:06:48 +0000	[thread overview]
Message-ID: <pull.2306.v4.git.1796245612.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2306.git.1794484985.gitgitgadget@gmail.com>

When using multiple worktrees, submodule settings stored in the repository
config are shared between all worktrees, even when they need to differ.

For example, different branches may use different URLs for the same
submodule. More importantly, sharing submodule.<name>.gitdir causes
submodule worktrees to share the same HEAD and index, even when the
corresponding superproject worktrees record different commits for the
submodule.

This series makes submodule settings worktree-specific when
extensions.worktreeConfig is enabled. It also keeps submodule.<name>.gitdir
relative for linked worktrees, so it continues to work when the worktree is
moved along with the main worktree.

Included commits:

 * [1/4] Keep submodule.<name>.gitdir relative for linked worktrees.
 * [2/4] Resolve symlinks in submodule.<name>.gitdir.
 * [3/4] Store submodule settings in the worktree config when
   extensions.worktreeConfig is enabled.
 * [4/4] Make git submodule init copy an existing gitdir setting to the
   current worktree config only when it belongs to that worktree.


Changes in v4
=============

 * [4/4] Resolve symlinks in submodule.<name>.gitdir value
 * [4/4] Fix the warning message


Changes in v3
=============

 * [1/4] Copy the path early, as relative_path may continue to use the
   provided buffer
 * [2/4] Add new commit to resolve symlinks in submodule.<name>.gitdir value
 * [3/4] Handle duplicate submodule.<name>.gitdir on 'git worktree add'
 * [3/4] Add more explanations
 * [4/4] Resolve symlinks in submodule_git_dir_matches_current_worktree()


Changes in v2
=============

 * Update the cover letter to better explain the problems this series
   addresses.
 * [1/3] Copy the string returned by worktree_git_path() early.
 * [2/3] Expand the explanation in the commit message for why the gitdir
   config is excluded from worktree add.
 * [3/3] Explain the case where the repository config contains a gitdir
   setting for another worktree, and warn when the setting is not copied.

Included commits:

 * [1/3] Keep submodule.<name>.gitdir relative for linked worktrees.
 * [2/3] Store submodule settings in the worktree config when
   extensions.worktreeConfig is enabled.
 * [3/3] Make git submodule init copy an existing gitdir setting to the
   current worktree config only when it belongs to that worktree.

Yoichi NAKAYAMA (4):
  submodule init: make submodule.<name>.gitdir relative for worktrees
  submodule init: resolve symlinks in submodule.<name>.gitdir
  submodule: store settings in worktree config when enabled
  submodule init: copy submodule.<name>.gitdir to config.worktree

 Documentation/config/extensions.adoc       |   9 +
 Documentation/config/submodule.adoc        |  14 +-
 Documentation/gitsubmodules.adoc           |  26 ++-
 builtin/submodule--helper.c                | 211 ++++++++++++++++-----
 builtin/worktree.c                         |  23 +++
 t/t2405-worktree-submodule.sh              | 157 +++++++++++++++
 t/t7425-submodule-gitdir-path-extension.sh | 180 +++++++++++++++++-
 7 files changed, 563 insertions(+), 57 deletions(-)


base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2306%2Fyoichi%2Fsubmodule-with-worktree-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2306/yoichi/submodule-with-worktree-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/2306

Range-diff vs v3:

 1:  6ed1297d8f = 1:  6ed1297d8f submodule init: make submodule.<name>.gitdir relative for worktrees
 2:  594eefeceb = 2:  594eefeceb submodule init: resolve symlinks in submodule.<name>.gitdir
 3:  f5d3f71748 = 3:  f5d3f71748 submodule: store settings in worktree config when enabled
 4:  3e2c161298 ! 4:  cfee53fc44 submodule init: copy submodule.<name>.gitdir to config.worktree
     @@ builtin/submodule--helper.c: struct init_cb {
      +					    "%s", gitdir))
      +		return false;
      +
     -+	if (strbuf_normalize_path(&submodule)) {
     ++	if (!strbuf_realpath_forgiving(&submodule, submodule.buf, 0)) {
      +		strbuf_release(&submodule);
      +		return false;
      +	}
     @@ builtin/submodule--helper.c: struct init_cb {
      +
      +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."
     ++"it does not point to a gitdir for the current worktree."
      +);
      +
       static int validate_and_set_submodule_gitdir(struct strbuf *gitdir_path,
     @@ builtin/submodule--helper.c: static int validate_and_set_submodule_gitdir(struct
      +			if (!matches ||
      +			    validate_submodule_git_dir(tmp, submodule_name)) {
      +				if (!matches)
     -+					warning(submodule_mismatch_warning, key);
     ++					warning(_(submodule_mismatch_warning),
     ++						key);
      +				free(tmp);
      +			} else {
      +				value = tmp;
     @@ t/t7425-submodule-gitdir-path-extension.sh: test_expect_success 'git submodule i
      +		test_cmp expect actual &&
      +		git config --worktree submodule.sub2.gitdir >actual &&
      +		echo ".git/modules/sub2" >expect &&
     ++		test_cmp expect actual
     ++	)
     ++'
     ++
     ++test_expect_success SYMLINKS 'git submodule init inherits related repository config by resolving symlinks' '
     ++	test_when_finished "rm -rf repo-clone-init-symlink" &&
     ++	git clone upstream repo-clone-init-symlink &&
     ++	(
     ++		cd repo-clone-init-symlink &&
     ++		git config core.repositoryformatversion 1 &&
     ++		git config extensions.submodulePathConfig true &&
     ++		git submodule init &&
     ++		git config submodule.sub1.gitdir >actual &&
     ++		echo ".git/modules/sub1" >expect &&
     ++		test_cmp expect actual &&
     ++		git config submodule.sub2.gitdir >actual &&
     ++		echo ".git/modules/sub2" >expect &&
     ++		test_cmp expect actual &&
     ++
     ++		ln -s ../repo-clone-init-symlink link &&
     ++		git config submodule.sub2.gitdir "$(pwd -P)/link/.git/modules/sub2" &&
     ++		git config extensions.worktreeConfig true &&
     ++
     ++		GIT_DIR=link/.git git submodule init sub1 2>err &&
     ++		test_must_be_empty err &&
     ++		git config --worktree submodule.sub1.gitdir >actual &&
     ++		git config --local submodule.sub1.gitdir >expect &&
     ++		test_cmp expect actual &&
     ++
     ++		git submodule init sub2 2>err &&
     ++		test_must_be_empty err &&
     ++		git config --worktree submodule.sub2.gitdir >actual &&
     ++		git config --local submodule.sub2.gitdir >expect &&
       		test_cmp expect actual
       	)
       '

-- 
gitgitgadget

  parent reply	other threads:[~2026-12-02 21:06 UTC|newest]

Thread overview: 30+ 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
2026-12-02 11:27       ` Yoichi NAKAYAMA
2026-12-02 21:06 ` Yoichi NAKAYAMA via GitGitGadget [this message]
2026-12-02 21:06   ` [PATCH v4 1/4] submodule init: make submodule.<name>.gitdir relative for worktrees Yoichi NAKAYAMA via GitGitGadget
2026-12-02 21:06   ` [PATCH v4 2/4] submodule init: resolve symlinks in submodule.<name>.gitdir Yoichi NAKAYAMA via GitGitGadget
2026-12-02 21:06   ` [PATCH v4 3/4] submodule: store settings in worktree config when enabled Yoichi NAKAYAMA via GitGitGadget
2026-12-02 21:06   ` [PATCH v4 4/4] submodule init: copy submodule.<name>.gitdir to config.worktree Yoichi NAKAYAMA via GitGitGadget

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=pull.2306.v4.git.1796245612.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --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