]>
Commit | Line | Data |
---|---|---|
f6f85861 SB |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test submodule absorbgitdirs | |
4 | ||
5 | This test verifies that `git submodue absorbgitdirs` moves a submodules git | |
6 | directory into the superproject. | |
7 | ' | |
8 | ||
d40c42e0 | 9 | TEST_PASSES_SANITIZE_LEAK=true |
f6f85861 SB |
10 | . ./test-lib.sh |
11 | ||
12 | test_expect_success 'setup a real submodule' ' | |
49eb1d38 | 13 | cwd="$(pwd)" && |
f6f85861 SB |
14 | git init sub1 && |
15 | test_commit -C sub1 first && | |
16 | git submodule add ./sub1 && | |
17 | test_tick && | |
18 | git commit -m superproject | |
19 | ' | |
20 | ||
21 | test_expect_success 'absorb the git dir' ' | |
49eb1d38 ÆAB |
22 | >expect && |
23 | >actual && | |
f6f85861 SB |
24 | >expect.1 && |
25 | >expect.2 && | |
26 | >actual.1 && | |
27 | >actual.2 && | |
28 | git status >expect.1 && | |
29 | git -C sub1 rev-parse HEAD >expect.2 && | |
49eb1d38 ÆAB |
30 | cat >expect <<-EOF && |
31 | Migrating git directory of '\''sub1'\'' from | |
32 | '\''$cwd/sub1/.git'\'' to | |
33 | '\''$cwd/.git/modules/sub1'\'' | |
34 | EOF | |
35 | git submodule absorbgitdirs 2>actual && | |
36 | test_cmp expect actual && | |
f6f85861 SB |
37 | git fsck && |
38 | test -f sub1/.git && | |
39 | test -d .git/modules/sub1 && | |
40 | git status >actual.1 && | |
41 | git -C sub1 rev-parse HEAD >actual.2 && | |
42 | test_cmp expect.1 actual.1 && | |
43 | test_cmp expect.2 actual.2 | |
44 | ' | |
45 | ||
64127575 | 46 | test_expect_success 'absorbing does not fail for deinitialized submodules' ' |
f6f85861 SB |
47 | test_when_finished "git submodule update --init" && |
48 | git submodule deinit --all && | |
49eb1d38 ÆAB |
49 | git submodule absorbgitdirs 2>err && |
50 | test_must_be_empty err && | |
f6f85861 SB |
51 | test -d .git/modules/sub1 && |
52 | test -d sub1 && | |
53 | ! test -e sub1/.git | |
54 | ' | |
55 | ||
56 | test_expect_success 'setup nested submodule' ' | |
57 | git init sub1/nested && | |
58 | test_commit -C sub1/nested first_nested && | |
59 | git -C sub1 submodule add ./nested && | |
60 | test_tick && | |
61 | git -C sub1 commit -m "add nested" && | |
62 | git add sub1 && | |
63 | git commit -m "sub1 to include nested submodule" | |
64 | ' | |
65 | ||
66 | test_expect_success 'absorb the git dir in a nested submodule' ' | |
67 | git status >expect.1 && | |
68 | git -C sub1/nested rev-parse HEAD >expect.2 && | |
49eb1d38 ÆAB |
69 | cat >expect <<-EOF && |
70 | Migrating git directory of '\''sub1/nested'\'' from | |
71 | '\''$cwd/sub1/nested/.git'\'' to | |
72 | '\''$cwd/.git/modules/sub1/modules/nested'\'' | |
73 | EOF | |
74 | git submodule absorbgitdirs 2>actual && | |
75 | test_cmp expect actual && | |
f6f85861 SB |
76 | test -f sub1/nested/.git && |
77 | test -d .git/modules/sub1/modules/nested && | |
78 | git status >actual.1 && | |
79 | git -C sub1/nested rev-parse HEAD >actual.2 && | |
80 | test_cmp expect.1 actual.1 && | |
81 | test_cmp expect.2 actual.2 | |
82 | ' | |
83 | ||
ec9629b3 SB |
84 | test_expect_success 're-setup nested submodule' ' |
85 | # un-absorb the direct submodule, to test if the nested submodule | |
86 | # is still correct (needs a rewrite of the gitfile only) | |
87 | rm -rf sub1/.git && | |
88 | mv .git/modules/sub1 sub1/.git && | |
89 | GIT_WORK_TREE=. git -C sub1 config --unset core.worktree && | |
90 | # fixup the nested submodule | |
91 | echo "gitdir: ../.git/modules/nested" >sub1/nested/.git && | |
92 | GIT_WORK_TREE=../../../nested git -C sub1/.git/modules/nested config \ | |
93 | core.worktree "../../../nested" && | |
94 | # make sure this re-setup is correct | |
98bf6674 SB |
95 | git status --ignore-submodules=none && |
96 | ||
97 | # also make sure this old setup does not regress | |
98 | git submodule update --init --recursive >out 2>err && | |
99 | test_must_be_empty out && | |
100 | test_must_be_empty err | |
ec9629b3 SB |
101 | ' |
102 | ||
103 | test_expect_success 'absorb the git dir in a nested submodule' ' | |
104 | git status >expect.1 && | |
105 | git -C sub1/nested rev-parse HEAD >expect.2 && | |
49eb1d38 ÆAB |
106 | cat >expect <<-EOF && |
107 | Migrating git directory of '\''sub1'\'' from | |
108 | '\''$cwd/sub1/.git'\'' to | |
109 | '\''$cwd/.git/modules/sub1'\'' | |
110 | EOF | |
111 | git submodule absorbgitdirs 2>actual && | |
112 | test_cmp expect actual && | |
ec9629b3 SB |
113 | test -f sub1/.git && |
114 | test -f sub1/nested/.git && | |
115 | test -d .git/modules/sub1/modules/nested && | |
116 | git status >actual.1 && | |
117 | git -C sub1/nested rev-parse HEAD >actual.2 && | |
118 | test_cmp expect.1 actual.1 && | |
119 | test_cmp expect.2 actual.2 | |
120 | ' | |
121 | ||
49eb1d38 ÆAB |
122 | test_expect_success 'absorb the git dir outside of primary worktree' ' |
123 | test_when_finished "rm -rf repo-bare.git" && | |
124 | git clone --bare . repo-bare.git && | |
125 | test_when_finished "rm -rf repo-wt" && | |
126 | git -C repo-bare.git worktree add ../repo-wt && | |
127 | ||
128 | test_when_finished "rm -f .gitconfig" && | |
129 | test_config_global protocol.file.allow always && | |
130 | git -C repo-wt submodule update --init && | |
131 | git init repo-wt/sub2 && | |
132 | test_commit -C repo-wt/sub2 A && | |
133 | git -C repo-wt submodule add ./sub2 sub2 && | |
134 | cat >expect <<-EOF && | |
135 | Migrating git directory of '\''sub2'\'' from | |
136 | '\''$cwd/repo-wt/sub2/.git'\'' to | |
137 | '\''$cwd/repo-bare.git/worktrees/repo-wt/modules/sub2'\'' | |
138 | EOF | |
139 | git -C repo-wt submodule absorbgitdirs 2>actual && | |
140 | test_cmp expect actual | |
141 | ' | |
142 | ||
f6f85861 SB |
143 | test_expect_success 'setup a gitlink with missing .gitmodules entry' ' |
144 | git init sub2 && | |
145 | test_commit -C sub2 first && | |
146 | git add sub2 && | |
147 | git commit -m superproject | |
148 | ' | |
149 | ||
150 | test_expect_success 'absorbing the git dir fails for incomplete submodules' ' | |
151 | git status >expect.1 && | |
152 | git -C sub2 rev-parse HEAD >expect.2 && | |
49eb1d38 ÆAB |
153 | cat >expect <<-\EOF && |
154 | fatal: could not lookup name for submodule '\''sub2'\'' | |
155 | EOF | |
156 | test_must_fail git submodule absorbgitdirs 2>actual && | |
157 | test_cmp expect actual && | |
f6f85861 SB |
158 | git -C sub2 fsck && |
159 | test -d sub2/.git && | |
160 | git status >actual && | |
161 | git -C sub2 rev-parse HEAD >actual.2 && | |
162 | test_cmp expect.1 actual.1 && | |
163 | test_cmp expect.2 actual.2 | |
164 | ' | |
165 | ||
166 | test_expect_success 'setup a submodule with multiple worktrees' ' | |
167 | # first create another unembedded git dir in a new submodule | |
168 | git init sub3 && | |
169 | test_commit -C sub3 first && | |
170 | git submodule add ./sub3 && | |
171 | test_tick && | |
172 | git commit -m "add another submodule" && | |
173 | git -C sub3 worktree add ../sub3_second_work_tree | |
174 | ' | |
175 | ||
176 | test_expect_success 'absorbing fails for a submodule with multiple worktrees' ' | |
49eb1d38 ÆAB |
177 | cat >expect <<-\EOF && |
178 | fatal: could not lookup name for submodule '\''sub2'\'' | |
179 | EOF | |
180 | test_must_fail git submodule absorbgitdirs 2>actual && | |
181 | test_cmp expect actual | |
f6f85861 SB |
182 | ' |
183 | ||
184 | test_done |