Git development
 help / color / mirror / Atom feed
From: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH 3/3] worktree: add --recurse-submodules flag to worktree add
Date: Thu, 16 Apr 2026 18:36:46 +0200	[thread overview]
Message-ID: <aeEP2lMfN9_qCTm1@RTX> (raw)

Add two new tests to t2405-worktree-submodule.sh:

1. "worktree add --recurse-submodules initializes submodules": verifies
    that the submodule working tree is populated and that "git diff
    --submodule" shows the expected commit difference after
    --recurse-submodules is used.

2. "submodule in --recurse-submodules worktree uses per-worktree gitdir":
    verifies the isolation guarantee -- the submodule gitdir for the
    linked worktree lives under $GIT_COMMON_DIR/worktrees/<id>/modules/,
    not under $GIT_COMMON_DIR/modules/, and the .git pointer file inside
    the working tree references that per-worktree location.  This ensures
    that removing the linked worktree also removes its submodule gitdirs,
    and that the main worktree's submodule gitdir is unaffected.

Also rename the existing test_expect_failure to clarify that it covers
the case without --recurse-submodules.

Signed-off-by: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
---
  t/t2405-worktree-submodule.sh | 24 +++++++++++++++++++++++-
  1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/t/t2405-worktree-submodule.sh b/t/t2405-worktree-submodule.sh
index 11018f37c7..5ffe0206dd 100755
--- a/t/t2405-worktree-submodule.sh
+++ b/t/t2405-worktree-submodule.sh
@@ -34,11 +34,33 @@ test_expect_success 'add superproject worktree' '
  	git -C main worktree add "$base_path/worktree" "$rev1_hash_main"
  '
  
-test_expect_failure 'submodule is checked out just after worktree add' '
+test_expect_failure 'submodule is checked out just after worktree add (without flag)' '
  	git -C worktree diff --submodule main"^!" >out &&
  	grep "file1 updated" out
  '
  
+test_expect_success 'worktree add --recurse-submodules initializes submodules' '
+	git -C main worktree add --recurse-submodules \
+		"$base_path/worktree-recurse" "$rev1_hash_main" &&
+	git -C worktree-recurse diff --submodule main"^!" >out &&
+	grep "file1 updated" out
+'
+
+test_expect_success 'submodule in --recurse-submodules worktree uses per-worktree gitdir' '
+	# The per-worktree submodule gitdir must live under the worktree entry,
+	# not under $GIT_COMMON_DIR/modules/, so it is cleaned up with the
+	# worktree and does not disturb the main worktree submodule.
+	sub_gitdir="$base_path/main/.git/worktrees/worktree-recurse/modules/sub" &&
+	test -d "$sub_gitdir" &&
+	# .git pointer in the working tree must reference the per-worktree gitdir
+	echo "gitdir: ../../main/.git/worktrees/worktree-recurse/modules/sub" \
+		>expect-gitfile &&
+	cat "$base_path/worktree-recurse/sub/.git" >actual-gitfile &&
+	test_cmp expect-gitfile actual-gitfile &&
+	# The working tree is populated (test_commit creates <name>.t files)
+	test -f "$base_path/worktree-recurse/sub/file1.t"
+'
+
  test_expect_success 'add superproject worktree and initialize submodules' '
  	git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" &&
  	git -C worktree-submodule-update submodule update



                 reply	other threads:[~2026-04-16 16:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=aeEP2lMfN9_qCTm1@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