]>
Commit | Line | Data |
---|---|---|
52e8370b DA |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 David Aguilar | |
4 | # | |
5 | ||
6 | test_description='git submodule sync | |
7 | ||
8 | These tests exercise the "git submodule sync" subcommand. | |
9 | ' | |
10 | ||
01dc8133 | 11 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
12 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
13 | ||
52e8370b DA |
14 | . ./test-lib.sh |
15 | ||
16 | test_expect_success setup ' | |
0d3beb71 TB |
17 | git config --global protocol.file.allow always && |
18 | ||
031129cb | 19 | echo file >file && |
52e8370b DA |
20 | git add file && |
21 | test_tick && | |
0eb032d8 | 22 | git commit -m upstream && |
52e8370b DA |
23 | git clone . super && |
24 | git clone super submodule && | |
031129cb JK |
25 | ( |
26 | cd submodule && | |
27 | git submodule add ../submodule sub-submodule && | |
28 | test_tick && | |
29 | git commit -m "sub-submodule" | |
44fa0ef5 | 30 | ) && |
031129cb JK |
31 | ( |
32 | cd super && | |
33 | git submodule add ../submodule submodule && | |
34 | test_tick && | |
35 | git commit -m "submodule" | |
52e8370b DA |
36 | ) && |
37 | git clone super super-clone && | |
031129cb JK |
38 | ( |
39 | cd super-clone && | |
40 | git submodule update --init --recursive | |
41 | ) && | |
33f072f8 | 42 | git clone super empty-clone && |
031129cb JK |
43 | ( |
44 | cd empty-clone && | |
45 | git submodule init | |
46 | ) && | |
49301c64 JS |
47 | git clone super top-only-clone && |
48 | git clone super relative-clone && | |
031129cb JK |
49 | ( |
50 | cd relative-clone && | |
51 | git submodule update --init --recursive | |
52 | ) && | |
44fa0ef5 | 53 | git clone super recursive-clone && |
031129cb JK |
54 | ( |
55 | cd recursive-clone && | |
56 | git submodule update --init --recursive | |
57 | ) | |
52e8370b DA |
58 | ' |
59 | ||
60 | test_expect_success 'change submodule' ' | |
031129cb JK |
61 | ( |
62 | cd submodule && | |
63 | echo second line >>file && | |
64 | test_tick && | |
65 | git commit -a -m "change submodule" | |
52e8370b DA |
66 | ) |
67 | ' | |
68 | ||
091a6eb0 | 69 | reset_submodule_urls () { |
091a6eb0 | 70 | ( |
e256eec7 | 71 | root=$(pwd) && |
091a6eb0 JK |
72 | cd super-clone/submodule && |
73 | git config remote.origin.url "$root/submodule" | |
74 | ) && | |
75 | ( | |
e256eec7 | 76 | root=$(pwd) && |
091a6eb0 JK |
77 | cd super-clone/submodule/sub-submodule && |
78 | git config remote.origin.url "$root/submodule" | |
79 | ) | |
80 | } | |
81 | ||
52e8370b | 82 | test_expect_success 'change submodule url' ' |
031129cb JK |
83 | ( |
84 | cd super && | |
85 | cd submodule && | |
01dc8133 | 86 | git checkout main && |
031129cb | 87 | git pull |
52e8370b DA |
88 | ) && |
89 | mv submodule moved-submodule && | |
031129cb JK |
90 | ( |
91 | cd moved-submodule && | |
92 | git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule && | |
93 | test_tick && | |
94 | git commit -a -m moved-sub-submodule | |
44fa0ef5 | 95 | ) && |
031129cb JK |
96 | ( |
97 | cd super && | |
98 | git config -f .gitmodules submodule.submodule.url ../moved-submodule && | |
99 | test_tick && | |
100 | git commit -a -m moved-submodule | |
52e8370b DA |
101 | ) |
102 | ' | |
103 | ||
104 | test_expect_success '"git submodule sync" should update submodule URLs' ' | |
031129cb JK |
105 | ( |
106 | cd super-clone && | |
107 | git pull --no-recurse-submodules && | |
108 | git submodule sync | |
52e8370b | 109 | ) && |
031129cb JK |
110 | test -d "$( |
111 | cd super-clone/submodule && | |
112 | git config remote.origin.url | |
abc06822 | 113 | )" && |
031129cb JK |
114 | test ! -d "$( |
115 | cd super-clone/submodule/sub-submodule && | |
116 | git config remote.origin.url | |
44fa0ef5 | 117 | )" && |
031129cb JK |
118 | ( |
119 | cd super-clone/submodule && | |
01dc8133 | 120 | git checkout main && |
031129cb | 121 | git pull |
0b9dca43 | 122 | ) && |
031129cb JK |
123 | ( |
124 | cd super-clone && | |
125 | test -d "$(git config submodule.submodule.url)" | |
52e8370b DA |
126 | ) |
127 | ' | |
128 | ||
44fa0ef5 | 129 | test_expect_success '"git submodule sync --recursive" should update all submodule URLs' ' |
031129cb JK |
130 | ( |
131 | cd super-clone && | |
132 | ( | |
133 | cd submodule && | |
134 | git pull --no-recurse-submodules | |
135 | ) && | |
136 | git submodule sync --recursive | |
44fa0ef5 | 137 | ) && |
031129cb JK |
138 | test -d "$( |
139 | cd super-clone/submodule && | |
140 | git config remote.origin.url | |
44fa0ef5 | 141 | )" && |
031129cb JK |
142 | test -d "$( |
143 | cd super-clone/submodule/sub-submodule && | |
144 | git config remote.origin.url | |
44fa0ef5 | 145 | )" && |
031129cb JK |
146 | ( |
147 | cd super-clone/submodule/sub-submodule && | |
01dc8133 | 148 | git checkout main && |
031129cb | 149 | git pull |
44fa0ef5 PH |
150 | ) |
151 | ' | |
152 | ||
091a6eb0 JK |
153 | test_expect_success 'reset submodule URLs' ' |
154 | reset_submodule_urls super-clone | |
155 | ' | |
156 | ||
157 | test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' ' | |
158 | ( | |
159 | cd super-clone && | |
160 | git pull --no-recurse-submodules && | |
161 | mkdir -p sub && | |
162 | cd sub && | |
163 | git submodule sync >../../output | |
164 | ) && | |
1edbaac3 | 165 | test_i18ngrep "\\.\\./submodule" output && |
091a6eb0 JK |
166 | test -d "$( |
167 | cd super-clone/submodule && | |
168 | git config remote.origin.url | |
169 | )" && | |
170 | test ! -d "$( | |
171 | cd super-clone/submodule/sub-submodule && | |
172 | git config remote.origin.url | |
173 | )" && | |
174 | ( | |
175 | cd super-clone/submodule && | |
01dc8133 | 176 | git checkout main && |
091a6eb0 JK |
177 | git pull |
178 | ) && | |
179 | ( | |
180 | cd super-clone && | |
181 | test -d "$(git config submodule.submodule.url)" | |
182 | ) | |
183 | ' | |
184 | ||
185 | test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' ' | |
186 | ( | |
187 | cd super-clone && | |
188 | ( | |
189 | cd submodule && | |
190 | git pull --no-recurse-submodules | |
191 | ) && | |
192 | mkdir -p sub && | |
193 | cd sub && | |
194 | git submodule sync --recursive >../../output | |
195 | ) && | |
1edbaac3 | 196 | test_i18ngrep "\\.\\./submodule/sub-submodule" output && |
091a6eb0 JK |
197 | test -d "$( |
198 | cd super-clone/submodule && | |
199 | git config remote.origin.url | |
200 | )" && | |
201 | test -d "$( | |
202 | cd super-clone/submodule/sub-submodule && | |
203 | git config remote.origin.url | |
204 | )" && | |
205 | ( | |
206 | cd super-clone/submodule/sub-submodule && | |
01dc8133 | 207 | git checkout main && |
091a6eb0 JK |
208 | git pull |
209 | ) | |
210 | ' | |
211 | ||
ccee6086 | 212 | test_expect_success '"git submodule sync" should update known submodule URLs' ' |
031129cb JK |
213 | ( |
214 | cd empty-clone && | |
215 | git pull && | |
216 | git submodule sync && | |
217 | test -d "$(git config submodule.submodule.url)" | |
33f072f8 AK |
218 | ) |
219 | ' | |
220 | ||
ccee6086 | 221 | test_expect_success '"git submodule sync" should not vivify uninteresting submodule' ' |
031129cb JK |
222 | ( |
223 | cd top-only-clone && | |
224 | git pull && | |
225 | git submodule sync && | |
226 | test -z "$(git config submodule.submodule.url)" && | |
227 | git submodule sync submodule && | |
228 | test -z "$(git config submodule.submodule.url)" | |
ccee6086 JH |
229 | ) |
230 | ' | |
231 | ||
758615e2 | 232 | test_expect_success '"git submodule sync" handles origin URL of the form foo' ' |
031129cb JK |
233 | ( |
234 | cd relative-clone && | |
235 | git remote set-url origin foo && | |
236 | git submodule sync && | |
237 | ( | |
238 | cd submodule && | |
239 | #actual fails with: "cannot strip off url foo | |
240 | test "$(git config remote.origin.url)" = "../submodule" | |
241 | ) | |
49301c64 JS |
242 | ) |
243 | ' | |
244 | ||
967b2c66 | 245 | test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' ' |
031129cb JK |
246 | ( |
247 | cd relative-clone && | |
248 | git remote set-url origin foo/bar && | |
249 | git submodule sync && | |
250 | ( | |
251 | cd submodule && | |
252 | #actual foo/submodule | |
253 | test "$(git config remote.origin.url)" = "../foo/submodule" | |
a82af054 | 254 | ) && |
031129cb JK |
255 | ( |
256 | cd submodule/sub-submodule && | |
257 | test "$(git config remote.origin.url)" != "../../foo/submodule" | |
258 | ) | |
44fa0ef5 PH |
259 | ) |
260 | ' | |
261 | ||
262 | test_expect_success '"git submodule sync --recursive" propagates changes in origin' ' | |
031129cb JK |
263 | ( |
264 | cd recursive-clone && | |
265 | git remote set-url origin foo/bar && | |
266 | git submodule sync --recursive && | |
267 | ( | |
268 | cd submodule && | |
269 | #actual foo/submodule | |
270 | test "$(git config remote.origin.url)" = "../foo/submodule" | |
a82af054 | 271 | ) && |
031129cb JK |
272 | ( |
273 | cd submodule/sub-submodule && | |
274 | test "$(git config remote.origin.url)" = "../../foo/submodule" | |
275 | ) | |
49301c64 JS |
276 | ) |
277 | ' | |
278 | ||
758615e2 | 279 | test_expect_success '"git submodule sync" handles origin URL of the form ./foo' ' |
031129cb JK |
280 | ( |
281 | cd relative-clone && | |
282 | git remote set-url origin ./foo && | |
283 | git submodule sync && | |
284 | ( | |
285 | cd submodule && | |
286 | #actual ./submodule | |
287 | test "$(git config remote.origin.url)" = "../submodule" | |
288 | ) | |
49301c64 JS |
289 | ) |
290 | ' | |
291 | ||
758615e2 | 292 | test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' ' |
031129cb JK |
293 | ( |
294 | cd relative-clone && | |
295 | git remote set-url origin ./foo/bar && | |
296 | git submodule sync && | |
297 | ( | |
298 | cd submodule && | |
299 | #actual ./foo/submodule | |
300 | test "$(git config remote.origin.url)" = "../foo/submodule" | |
301 | ) | |
49301c64 JS |
302 | ) |
303 | ' | |
304 | ||
967b2c66 | 305 | test_expect_success '"git submodule sync" handles origin URL of the form ../foo' ' |
031129cb JK |
306 | ( |
307 | cd relative-clone && | |
308 | git remote set-url origin ../foo && | |
309 | git submodule sync && | |
310 | ( | |
311 | cd submodule && | |
312 | #actual ../submodule | |
313 | test "$(git config remote.origin.url)" = "../../submodule" | |
314 | ) | |
49301c64 JS |
315 | ) |
316 | ' | |
317 | ||
967b2c66 | 318 | test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' ' |
031129cb JK |
319 | ( |
320 | cd relative-clone && | |
321 | git remote set-url origin ../foo/bar && | |
322 | git submodule sync && | |
323 | ( | |
324 | cd submodule && | |
325 | #actual ../foo/submodule | |
326 | test "$(git config remote.origin.url)" = "../../foo/submodule" | |
327 | ) | |
49301c64 JS |
328 | ) |
329 | ' | |
330 | ||
967b2c66 | 331 | test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' ' |
031129cb JK |
332 | ( |
333 | cd relative-clone && | |
334 | git remote set-url origin ../foo/bar && | |
335 | mkdir -p a/b/c && | |
336 | ( | |
337 | cd a/b/c && | |
338 | git init && | |
339 | >.gitignore && | |
340 | git add .gitignore && | |
341 | test_tick && | |
342 | git commit -m "initial commit" | |
343 | ) && | |
344 | git submodule add ../bar/a/b/c ./a/b/c && | |
345 | git submodule sync && | |
346 | ( | |
347 | cd a/b/c && | |
348 | #actual ../foo/bar/a/b/c | |
349 | test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c" | |
350 | ) | |
49301c64 JS |
351 | ) |
352 | ' | |
353 | ||
354 | ||
52e8370b | 355 | test_done |