{"thread":{"id":"65498","subject":"[PATCH 3/3] worktree: add --recurse-submodules flag to worktree add","startedAt":"2026-04-16T16:36:48Z","lastAt":"2026-04-16T16:36:48Z","messageCount":1,"participants":["Jimmy Aguilar Mena"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"541754","messageId":"aeEP2lMfN9_qCTm1@RTX","threadId":"65498","inReplyTo":null,"subject":"[PATCH 3/3] worktree: add --recurse-submodules flag to worktree add","fromName":"Jimmy Aguilar Mena","fromEmail":"kratsbinovish@gmail.com","sentAt":"2026-04-16T16:36:46Z","receivedAt":"2026-04-16T16:36:48Z","isPatch":true,"body":"Add two new tests to t2405-worktree-submodule.sh:\n\n1. \"worktree add --recurse-submodules initializes submodules\": verifies\n    that the submodule working tree is populated and that \"git diff\n    --submodule\" shows the expected commit difference after\n    --recurse-submodules is used.\n\n2. \"submodule in --recurse-submodules worktree uses per-worktree gitdir\":\n    verifies the isolation guarantee -- the submodule gitdir for the\n    linked worktree lives under $GIT_COMMON_DIR/worktrees/<id>/modules/,\n    not under $GIT_COMMON_DIR/modules/, and the .git pointer file inside\n    the working tree references that per-worktree location.  This ensures\n    that removing the linked worktree also removes its submodule gitdirs,\n    and that the main worktree's submodule gitdir is unaffected.\n\nAlso rename the existing test_expect_failure to clarify that it covers\nthe case without --recurse-submodules.\n\nSigned-off-by: Jimmy Aguilar Mena <kratsbinovish@gmail.com>\n---\n  t/t2405-worktree-submodule.sh | 24 +++++++++++++++++++++++-\n  1 file changed, 23 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t2405-worktree-submodule.sh b/t/t2405-worktree-submodule.sh\nindex 11018f37c7..5ffe0206dd 100755\n--- a/t/t2405-worktree-submodule.sh\n+++ b/t/t2405-worktree-submodule.sh\n@@ -34,11 +34,33 @@ test_expect_success 'add superproject worktree' '\n  \tgit -C main worktree add \"$base_path/worktree\" \"$rev1_hash_main\"\n  '\n  \n-test_expect_failure 'submodule is checked out just after worktree add' '\n+test_expect_failure 'submodule is checked out just after worktree add (without flag)' '\n  \tgit -C worktree diff --submodule main\"^!\" >out &&\n  \tgrep \"file1 updated\" out\n  '\n  \n+test_expect_success 'worktree add --recurse-submodules initializes submodules' '\n+\tgit -C main worktree add --recurse-submodules \\\n+\t\t\"$base_path/worktree-recurse\" \"$rev1_hash_main\" &&\n+\tgit -C worktree-recurse diff --submodule main\"^!\" >out &&\n+\tgrep \"file1 updated\" out\n+'\n+\n+test_expect_success 'submodule in --recurse-submodules worktree uses per-worktree gitdir' '\n+\t# The per-worktree submodule gitdir must live under the worktree entry,\n+\t# not under $GIT_COMMON_DIR/modules/, so it is cleaned up with the\n+\t# worktree and does not disturb the main worktree submodule.\n+\tsub_gitdir=\"$base_path/main/.git/worktrees/worktree-recurse/modules/sub\" &&\n+\ttest -d \"$sub_gitdir\" &&\n+\t# .git pointer in the working tree must reference the per-worktree gitdir\n+\techo \"gitdir: ../../main/.git/worktrees/worktree-recurse/modules/sub\" \\\n+\t\t>expect-gitfile &&\n+\tcat \"$base_path/worktree-recurse/sub/.git\" >actual-gitfile &&\n+\ttest_cmp expect-gitfile actual-gitfile &&\n+\t# The working tree is populated (test_commit creates <name>.t files)\n+\ttest -f \"$base_path/worktree-recurse/sub/file1.t\"\n+'\n+\n  test_expect_success 'add superproject worktree and initialize submodules' '\n  \tgit -C main worktree add \"$base_path/worktree-submodule-update\" \"$rev1_hash_main\" &&\n  \tgit -C worktree-submodule-update submodule update\n\n\n"}]}