]>
Commit | Line | Data |
---|---|---|
df56607d MK |
1 | #!/bin/sh |
2 | ||
773c60a4 | 3 | test_description='Combination of submodules and multiple worktrees' |
df56607d | 4 | |
883b98ef | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
df56607d MK |
8 | . ./test-lib.sh |
9 | ||
10 | base_path=$(pwd -P) | |
11 | ||
4eaadc84 | 12 | test_expect_success 'setup: create origin repos' ' |
99f4abb8 | 13 | git config --global protocol.file.allow always && |
4eaadc84 PB |
14 | git init origin/sub && |
15 | test_commit -C origin/sub file1 && | |
16 | git init origin/main && | |
a9472afb | 17 | test_commit -C origin/main first && |
4eaadc84 PB |
18 | git -C origin/main submodule add ../sub && |
19 | git -C origin/main commit -m "add sub" && | |
20 | test_commit -C origin/sub "file1 updated" file1 file1updated file1updated && | |
31158c7e | 21 | git -C origin/main/sub pull && |
4eaadc84 PB |
22 | git -C origin/main add sub && |
23 | git -C origin/main commit -m "sub updated" | |
31158c7e SB |
24 | ' |
25 | ||
129510a0 PB |
26 | test_expect_success 'setup: clone superproject to create main worktree' ' |
27 | git clone --recursive "$base_path/origin/main" main | |
31158c7e | 28 | ' |
df56607d MK |
29 | |
30 | rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1") | |
31 | rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1") | |
32 | ||
129510a0 PB |
33 | test_expect_success 'add superproject worktree' ' |
34 | git -C main worktree add "$base_path/worktree" "$rev1_hash_main" | |
31158c7e | 35 | ' |
df56607d | 36 | |
129510a0 | 37 | test_expect_failure 'submodule is checked out just after worktree add' ' |
883b98ef | 38 | git -C worktree diff --submodule main"^!" >out && |
31158c7e SB |
39 | grep "file1 updated" out |
40 | ' | |
df56607d | 41 | |
129510a0 PB |
42 | test_expect_success 'add superproject worktree and initialize submodules' ' |
43 | git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" && | |
44 | git -C worktree-submodule-update submodule update | |
31158c7e | 45 | ' |
df56607d | 46 | |
129510a0 | 47 | test_expect_success 'submodule is checked out just after submodule update in linked worktree' ' |
883b98ef | 48 | git -C worktree-submodule-update diff --submodule main"^!" >out && |
31158c7e SB |
49 | grep "file1 updated" out |
50 | ' | |
df56607d | 51 | |
129510a0 PB |
52 | test_expect_success 'add superproject worktree and manually add submodule worktree' ' |
53 | git -C main worktree add "$base_path/linked_submodule" "$rev1_hash_main" && | |
54 | git -C main/sub worktree add "$base_path/linked_submodule/sub" "$rev1_hash_sub" | |
31158c7e | 55 | ' |
11f9dd71 | 56 | |
129510a0 | 57 | test_expect_success 'submodule is checked out after manually adding submodule worktree' ' |
883b98ef | 58 | git -C linked_submodule diff --submodule main"^!" >out && |
31158c7e SB |
59 | grep "file1 updated" out |
60 | ' | |
11f9dd71 | 61 | |
a9472afb PB |
62 | test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' ' |
63 | git -C main worktree add "$base_path/checkout-recurse" --detach && | |
64 | git -C checkout-recurse submodule update --init && | |
65 | echo "gitdir: ../../main/.git/worktrees/checkout-recurse/modules/sub" >expect-gitfile && | |
66 | cat checkout-recurse/sub/.git >actual-gitfile && | |
67 | test_cmp expect-gitfile actual-gitfile && | |
68 | git -C main/sub rev-parse HEAD >expect-head-main && | |
69 | git -C checkout-recurse checkout --recurse-submodules HEAD~1 && | |
70 | cat checkout-recurse/sub/.git >actual-gitfile && | |
71 | git -C main/sub rev-parse HEAD >actual-head-main && | |
72 | test_cmp expect-gitfile actual-gitfile && | |
73 | test_cmp expect-head-main actual-head-main | |
74 | ' | |
75 | ||
76 | test_expect_success 'core.worktree is removed in $GIT_DIR/modules/<name>/config, not in $GIT_COMMON_DIR/modules/<name>/config' ' | |
77 | echo "../../../sub" >expect-main && | |
78 | git -C main/sub config --get core.worktree >actual-main && | |
79 | test_cmp expect-main actual-main && | |
80 | echo "../../../../../../checkout-recurse/sub" >expect-linked && | |
81 | git -C checkout-recurse/sub config --get core.worktree >actual-linked && | |
82 | test_cmp expect-linked actual-linked && | |
83 | git -C checkout-recurse checkout --recurse-submodules first && | |
84 | test_expect_code 1 git -C main/.git/worktrees/checkout-recurse/modules/sub config --get core.worktree >linked-config && | |
85 | test_must_be_empty linked-config && | |
86 | git -C main/sub config --get core.worktree >actual-main && | |
87 | test_cmp expect-main actual-main | |
88 | ' | |
89 | ||
90 | test_expect_success 'unsetting core.worktree does not prevent running commands directly against the submodule repository' ' | |
91 | git -C main/.git/worktrees/checkout-recurse/modules/sub log | |
92 | ' | |
93 | ||
df56607d | 94 | test_done |