Skip to content

pr-2306/yoichi/submodule-with-worktree-v2

tagged this 21 Nov 15:10
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.

The changes include:

 * [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.

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.

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

 Documentation/config/submodule.adoc        |   3 +-
 builtin/submodule--helper.c                | 213 ++++++++++++++++-----
 builtin/worktree.c                         |  23 +++
 t/t2405-worktree-submodule.sh              | 129 +++++++++++++
 t/t7425-submodule-gitdir-path-extension.sh | 135 +++++++++++++
 5 files changed, 451 insertions(+), 52 deletions(-)

base-commit: f7de81456940dd6f3274e461149bba12965de609

Submitted-As: https://lore.kernel.org/git/pull.2306.v2.git.1795273853.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2306.git.1794484985.gitgitgadget@gmail.com
Assets 2
Loading