3 test_description='Combination of submodules and multiple worktrees'
9 test_expect_success 'setup: create origin repos' '
10 git init origin/sub &&
11 test_commit -C origin/sub file1 &&
12 git init origin/main &&
13 test_commit -C origin/main first &&
14 git -C origin/main submodule add ../sub &&
15 git -C origin/main commit -m "add sub" &&
16 test_commit -C origin/sub "file1 updated" file1 file1updated file1updated &&
17 git -C origin/main/sub pull &&
18 git -C origin/main add sub &&
19 git -C origin/main commit -m "sub updated"
22 test_expect_success 'setup: clone superproject to create main worktree' '
23 git clone --recursive "$base_path/origin/main" main
26 rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
27 rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
29 test_expect_success 'add superproject worktree' '
30 git -C main worktree add "$base_path/worktree" "$rev1_hash_main"
33 test_expect_failure 'submodule is checked out just after worktree add' '
34 git -C worktree diff --submodule master"^!" >out &&
35 grep "file1 updated" out
38 test_expect_success 'add superproject worktree and initialize submodules' '
39 git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" &&
40 git -C worktree-submodule-update submodule update
43 test_expect_success 'submodule is checked out just after submodule update in linked worktree' '
44 git -C worktree-submodule-update diff --submodule master"^!" >out &&
45 grep "file1 updated" out
48 test_expect_success 'add superproject worktree and manually add submodule worktree' '
49 git -C main worktree add "$base_path/linked_submodule" "$rev1_hash_main" &&
50 git -C main/sub worktree add "$base_path/linked_submodule/sub" "$rev1_hash_sub"
53 test_expect_success 'submodule is checked out after manually adding submodule worktree' '
54 git -C linked_submodule diff --submodule master"^!" >out &&
55 grep "file1 updated" out
58 test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' '
59 git -C main worktree add "$base_path/checkout-recurse" --detach &&
60 git -C checkout-recurse submodule update --init &&
61 echo "gitdir: ../../main/.git/worktrees/checkout-recurse/modules/sub" >expect-gitfile &&
62 cat checkout-recurse/sub/.git >actual-gitfile &&
63 test_cmp expect-gitfile actual-gitfile &&
64 git -C main/sub rev-parse HEAD >expect-head-main &&
65 git -C checkout-recurse checkout --recurse-submodules HEAD~1 &&
66 cat checkout-recurse/sub/.git >actual-gitfile &&
67 git -C main/sub rev-parse HEAD >actual-head-main &&
68 test_cmp expect-gitfile actual-gitfile &&
69 test_cmp expect-head-main actual-head-main
72 test_expect_success 'core.worktree is removed in $GIT_DIR/modules/<name>/config, not in $GIT_COMMON_DIR/modules/<name>/config' '
73 echo "../../../sub" >expect-main &&
74 git -C main/sub config --get core.worktree >actual-main &&
75 test_cmp expect-main actual-main &&
76 echo "../../../../../../checkout-recurse/sub" >expect-linked &&
77 git -C checkout-recurse/sub config --get core.worktree >actual-linked &&
78 test_cmp expect-linked actual-linked &&
79 git -C checkout-recurse checkout --recurse-submodules first &&
80 test_expect_code 1 git -C main/.git/worktrees/checkout-recurse/modules/sub config --get core.worktree >linked-config &&
81 test_must_be_empty linked-config &&
82 git -C main/sub config --get core.worktree >actual-main &&
83 test_cmp expect-main actual-main
86 test_expect_success 'unsetting core.worktree does not prevent running commands directly against the submodule repository' '
87 git -C main/.git/worktrees/checkout-recurse/modules/sub log