From: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 0/3] worktree: add --recurse-submodules support to git worktree add
Date: Thu, 16 Apr 2026 18:32:18 +0200 [thread overview]
Message-ID: <aeEMU-ohKz2tnSWq@RTX> (raw)
This series implements the native --recurse-submodules flag for
"git worktree add" discussed in the earlier RFC thread.
The approach follows Phillip Wood's and Junio's feedback: each linked
worktree gets its own per-worktree submodule gitdir under
$GIT_COMMON_DIR/worktrees/<id>/modules/<name>/, so HEAD, refs, and
the index are independent per worktree while pack files and loose
objects are shared via hardlinks. The gitdir isolation is the same
model git worktree already uses for the superproject.
Patch 1 adds the --recurse-submodules flag to builtin/worktree.c and
calls "git submodule update --init --recursive" from within the new
worktree after checkout.
Patch 2 teaches clone_submodule() in builtin/submodule--helper.c to
detect when the main worktree already has the submodule cloned and
reuse it via "git clone --local --no-checkout --separate-git-dir"
instead of fetching from the remote URL. This avoids redundant
network access and disk use: the objects are already present locally.
Patch 3 adds tests to t2405-worktree-submodule.sh covering both the
happy path and the gitdir-isolation invariant.
Cleanup is automatic: submodule gitdirs under worktrees/<id>/modules/
are removed when "git worktree remove" calls remove_dir_recursively()
on the worktree entry, exactly as with the superproject's per-worktree
state.
Changes since the RFC:
- Replaced the shell-script cp -al prototype with a native C
implementation in builtin/worktree.c and builtin/submodule--helper.c.
- Per-worktree gitdir isolation is now handled by the existing
submodule_name_to_gitdir() path; no extra plumbing is needed.
- Added t2405 tests verifying both behaviour and gitdir placement.
Jimmy Aguilar Mena (3):
worktree: add --recurse-submodules flag to worktree add
submodule--helper: reuse main-worktree gitdir in linked worktrees
t2405: add tests for worktree add --recurse-submodules
builtin/submodule--helper.c | 54 +++++++++++++++++++++++++++++++++++
builtin/worktree.c | 23 +++++++++++++++
t/t2405-worktree-submodule.sh | 24 +++++++++++++++-
3 files changed, 100 insertions(+), 1 deletion(-)
next reply other threads:[~2026-04-16 16:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 16:32 Jimmy Aguilar Mena [this message]
2026-04-16 17:05 ` [PATCH 0/3] worktree: add --recurse-submodules support to git worktree add Junio C Hamano
2026-04-16 18:38 ` Phillip Wood
2026-04-17 9:38 ` Phillip Wood
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=aeEMU-ohKz2tnSWq@RTX \
--to=kratsbinovish@gmail.com \
--cc=CAPSFGa8uu9CEEPH3XVjfN5VEOfcnb2p8YgXVuansjKc0S2S_tA@mail.gmail.com \
--cc=git@vger.kernel.org \
/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