]>
Commit | Line | Data |
---|---|---|
ca2cedba PH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Red Hat, Inc. | |
4 | # | |
5 | ||
6 | test_description='Test updating submodules | |
7 | ||
8 | This test verifies that "git submodule update" detaches the HEAD of the | |
42b49178 | 9 | submodule and "git submodule update --rebase/--merge" does not detach the HEAD. |
ca2cedba PH |
10 | ' |
11 | ||
01dc8133 | 12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
14 | ||
ca2cedba PH |
15 | . ./test-lib.sh |
16 | ||
17 | ||
18 | compare_head() | |
19 | { | |
01dc8133 | 20 | sha_main=$(git rev-list --max-count=1 main) |
848351b2 | 21 | sha_head=$(git rev-list --max-count=1 HEAD) |
ca2cedba | 22 | |
01dc8133 | 23 | test "$sha_main" = "$sha_head" |
ca2cedba PH |
24 | } |
25 | ||
26 | ||
27 | test_expect_success 'setup a submodule tree' ' | |
28 | echo file > file && | |
29 | git add file && | |
30 | test_tick && | |
4bf9dd97 | 31 | git commit -m upstream && |
ca2cedba PH |
32 | git clone . super && |
33 | git clone super submodule && | |
c9c8c56e SB |
34 | git clone super rebasing && |
35 | git clone super merging && | |
322bb6e1 | 36 | git clone super none && |
ca2cedba PH |
37 | (cd super && |
38 | git submodule add ../submodule submodule && | |
39 | test_tick && | |
40 | git commit -m "submodule" && | |
41 | git submodule init submodule | |
42 | ) && | |
43 | (cd submodule && | |
44 | echo "line2" > file && | |
45 | git add file && | |
46 | git commit -m "Commit 2" | |
47 | ) && | |
48 | (cd super && | |
49 | (cd submodule && | |
50 | git pull --rebase origin | |
51 | ) && | |
52 | git add submodule && | |
53 | git commit -m "submodule update" | |
c9c8c56e SB |
54 | ) && |
55 | (cd super && | |
56 | git submodule add ../rebasing rebasing && | |
57 | test_tick && | |
58 | git commit -m "rebasing" | |
59 | ) && | |
60 | (cd super && | |
61 | git submodule add ../merging merging && | |
62 | test_tick && | |
63 | git commit -m "rebasing" | |
d5b99f35 | 64 | ) && |
322bb6e1 HV |
65 | (cd super && |
66 | git submodule add ../none none && | |
67 | test_tick && | |
68 | git commit -m "none" | |
c1ab00fb SB |
69 | ) && |
70 | git clone . recursivesuper && | |
8de19d6b | 71 | ( cd recursivesuper && |
c1ab00fb | 72 | git submodule add ../super super |
322bb6e1 | 73 | ) |
ca2cedba PH |
74 | ' |
75 | ||
f0a96e8d JS |
76 | test_expect_success 'update --remote falls back to using HEAD' ' |
77 | test_create_repo main-branch-submodule && | |
78 | test_commit -C main-branch-submodule initial && | |
79 | ||
80 | test_create_repo main-branch && | |
81 | git -C main-branch submodule add ../main-branch-submodule && | |
82 | git -C main-branch commit -m add-submodule && | |
83 | ||
84 | git -C main-branch-submodule switch -c hello && | |
85 | test_commit -C main-branch-submodule world && | |
86 | ||
87 | git clone --recursive main-branch main-branch-clone && | |
88 | git -C main-branch-clone submodule update --remote main-branch-submodule && | |
89 | test_path_exists main-branch-clone/main-branch-submodule/world.t | |
90 | ' | |
91 | ||
ca2cedba PH |
92 | test_expect_success 'submodule update detaching the HEAD ' ' |
93 | (cd super/submodule && | |
94 | git reset --hard HEAD~1 | |
95 | ) && | |
96 | (cd super && | |
97 | (cd submodule && | |
98 | compare_head | |
99 | ) && | |
100 | git submodule update submodule && | |
101 | cd submodule && | |
091a6eb0 JK |
102 | ! compare_head |
103 | ) | |
104 | ' | |
105 | ||
106 | test_expect_success 'submodule update from subdirectory' ' | |
107 | (cd super/submodule && | |
108 | git reset --hard HEAD~1 | |
109 | ) && | |
110 | mkdir super/sub && | |
111 | (cd super/sub && | |
112 | (cd ../submodule && | |
113 | compare_head | |
114 | ) && | |
115 | git submodule update ../submodule && | |
116 | cd ../submodule && | |
ca2cedba PH |
117 | ! compare_head |
118 | ) | |
119 | ' | |
120 | ||
c1ab00fb SB |
121 | supersha1=$(git -C super rev-parse HEAD) |
122 | mergingsha1=$(git -C super/merging rev-parse HEAD) | |
123 | nonesha1=$(git -C super/none rev-parse HEAD) | |
124 | rebasingsha1=$(git -C super/rebasing rev-parse HEAD) | |
125 | submodulesha1=$(git -C super/submodule rev-parse HEAD) | |
126 | pwd=$(pwd) | |
127 | ||
128 | cat <<EOF >expect | |
129 | Submodule path '../super': checked out '$supersha1' | |
c1ab00fb SB |
130 | Submodule path '../super/merging': checked out '$mergingsha1' |
131 | Submodule path '../super/none': checked out '$nonesha1' | |
132 | Submodule path '../super/rebasing': checked out '$rebasingsha1' | |
133 | Submodule path '../super/submodule': checked out '$submodulesha1' | |
134 | EOF | |
135 | ||
c66410ed | 136 | cat <<EOF >expect2 |
0b7d324e JS |
137 | Cloning into '$pwd/recursivesuper/super/merging'... |
138 | Cloning into '$pwd/recursivesuper/super/none'... | |
139 | Cloning into '$pwd/recursivesuper/super/rebasing'... | |
140 | Cloning into '$pwd/recursivesuper/super/submodule'... | |
c66410ed SB |
141 | Submodule 'merging' ($pwd/merging) registered for path '../super/merging' |
142 | Submodule 'none' ($pwd/none) registered for path '../super/none' | |
143 | Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing' | |
144 | Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule' | |
c66410ed | 145 | done. |
c66410ed | 146 | done. |
c66410ed | 147 | done. |
c66410ed SB |
148 | done. |
149 | EOF | |
150 | ||
c1ab00fb SB |
151 | test_expect_success 'submodule update --init --recursive from subdirectory' ' |
152 | git -C recursivesuper/super reset --hard HEAD^ && | |
153 | (cd recursivesuper && | |
154 | mkdir tmp && | |
155 | cd tmp && | |
c66410ed | 156 | git submodule update --init --recursive ../super >../../actual 2>../../actual2 |
c1ab00fb | 157 | ) && |
1108cea7 | 158 | test_cmp expect actual && |
0b7d324e | 159 | sort actual2 >actual2.sorted && |
1108cea7 | 160 | test_cmp expect2 actual2.sorted |
c1ab00fb SB |
161 | ' |
162 | ||
6e7c14e6 SB |
163 | cat <<EOF >expect2 |
164 | Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub' | |
165 | EOF | |
166 | ||
167 | test_expect_success 'submodule update --init from and of subdirectory' ' | |
168 | git init withsubs && | |
169 | (cd withsubs && | |
170 | mkdir foo && | |
171 | git submodule add "$(pwd)/../rebasing" foo/sub && | |
172 | (cd foo && | |
173 | git submodule deinit -f sub && | |
174 | git submodule update --init sub 2>../../actual2 | |
175 | ) | |
176 | ) && | |
1108cea7 | 177 | test_cmp expect2 actual2 |
6e7c14e6 SB |
178 | ' |
179 | ||
e5f522d6 JL |
180 | test_expect_success 'submodule update does not fetch already present commits' ' |
181 | (cd submodule && | |
182 | echo line3 >> file && | |
183 | git add file && | |
184 | test_tick && | |
185 | git commit -m "upstream line3" | |
186 | ) && | |
187 | (cd super/submodule && | |
188 | head=$(git rev-parse --verify HEAD) && | |
bd482d6e | 189 | echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected && |
e5f522d6 JL |
190 | git reset --hard HEAD~1 |
191 | ) && | |
192 | (cd super && | |
193 | git submodule update > ../actual 2> ../actual.err | |
194 | ) && | |
1108cea7 | 195 | test_cmp expected actual && |
7e9055bb | 196 | test_must_be_empty actual.err |
e5f522d6 JL |
197 | ' |
198 | ||
9db31bdf NMC |
199 | test_expect_success 'submodule update should fail due to local changes' ' |
200 | (cd super/submodule && | |
201 | git reset --hard HEAD~1 && | |
202 | echo "local change" > file | |
203 | ) && | |
204 | (cd super && | |
205 | (cd submodule && | |
206 | compare_head | |
207 | ) && | |
208 | test_must_fail git submodule update submodule | |
209 | ) | |
210 | ' | |
211 | test_expect_success 'submodule update should throw away changes with --force ' ' | |
212 | (cd super && | |
213 | (cd submodule && | |
214 | compare_head | |
215 | ) && | |
216 | git submodule update --force submodule && | |
217 | cd submodule && | |
218 | ! compare_head | |
219 | ) | |
220 | ' | |
221 | ||
01d47215 SZ |
222 | test_expect_success 'submodule update --force forcibly checks out submodules' ' |
223 | (cd super && | |
224 | (cd submodule && | |
225 | rm -f file | |
226 | ) && | |
227 | git submodule update --force submodule && | |
228 | (cd submodule && | |
229 | test "$(git status -s file)" = "" | |
230 | ) | |
231 | ) | |
232 | ' | |
233 | ||
06b1abb5 TK |
234 | test_expect_success 'submodule update --remote should fetch upstream changes' ' |
235 | (cd submodule && | |
236 | echo line4 >> file && | |
237 | git add file && | |
238 | test_tick && | |
239 | git commit -m "upstream line4" | |
240 | ) && | |
241 | (cd super && | |
242 | git submodule update --remote --force submodule && | |
243 | cd submodule && | |
244 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)" | |
245 | ) | |
246 | ' | |
247 | ||
4d7bc52b SB |
248 | test_expect_success 'submodule update --remote should fetch upstream changes with .' ' |
249 | ( | |
250 | cd super && | |
251 | git config -f .gitmodules submodule."submodule".branch "." && | |
252 | git add .gitmodules && | |
253 | git commit -m "submodules: update from the respective superproject branch" | |
254 | ) && | |
255 | ( | |
256 | cd submodule && | |
257 | echo line4a >> file && | |
258 | git add file && | |
259 | test_tick && | |
260 | git commit -m "upstream line4a" && | |
261 | git checkout -b test-branch && | |
262 | test_commit on-test-branch | |
263 | ) && | |
264 | ( | |
265 | cd super && | |
266 | git submodule update --remote --force submodule && | |
8de19d6b | 267 | git -C submodule log -1 --oneline >actual && |
01dc8133 | 268 | git -C ../submodule log -1 --oneline main >expect && |
4d7bc52b SB |
269 | test_cmp expect actual && |
270 | git checkout -b test-branch && | |
271 | git submodule update --remote --force submodule && | |
8de19d6b SG |
272 | git -C submodule log -1 --oneline >actual && |
273 | git -C ../submodule log -1 --oneline test-branch >expect && | |
4d7bc52b | 274 | test_cmp expect actual && |
01dc8133 | 275 | git checkout main && |
4d7bc52b SB |
276 | git branch -d test-branch && |
277 | git reset --hard HEAD^ | |
278 | ) | |
279 | ' | |
280 | ||
06b1abb5 TK |
281 | test_expect_success 'local config should override .gitmodules branch' ' |
282 | (cd submodule && | |
4d7bc52b | 283 | git checkout test-branch && |
06b1abb5 TK |
284 | echo line5 >> file && |
285 | git add file && | |
286 | test_tick && | |
287 | git commit -m "upstream line5" && | |
01dc8133 | 288 | git checkout main |
06b1abb5 TK |
289 | ) && |
290 | (cd super && | |
291 | git config submodule.submodule.branch test-branch && | |
292 | git submodule update --remote --force submodule && | |
293 | cd submodule && | |
294 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)" | |
295 | ) | |
296 | ' | |
297 | ||
01dc8133 | 298 | test_expect_success 'submodule update --rebase staying on main' ' |
ca2cedba | 299 | (cd super/submodule && |
01dc8133 | 300 | git checkout main |
ca2cedba PH |
301 | ) && |
302 | (cd super && | |
303 | (cd submodule && | |
304 | compare_head | |
305 | ) && | |
306 | git submodule update --rebase submodule && | |
307 | cd submodule && | |
308 | compare_head | |
309 | ) | |
310 | ' | |
311 | ||
01dc8133 | 312 | test_expect_success 'submodule update --merge staying on main' ' |
42b49178 JH |
313 | (cd super/submodule && |
314 | git reset --hard HEAD~1 | |
315 | ) && | |
316 | (cd super && | |
317 | (cd submodule && | |
318 | compare_head | |
319 | ) && | |
320 | git submodule update --merge submodule && | |
321 | cd submodule && | |
322 | compare_head | |
323 | ) | |
324 | ' | |
325 | ||
32948425 | 326 | test_expect_success 'submodule update - rebase in .git/config' ' |
ca2cedba | 327 | (cd super && |
32948425 | 328 | git config submodule.submodule.update rebase |
ca2cedba PH |
329 | ) && |
330 | (cd super/submodule && | |
331 | git reset --hard HEAD~1 | |
332 | ) && | |
333 | (cd super && | |
334 | (cd submodule && | |
335 | compare_head | |
336 | ) && | |
337 | git submodule update submodule && | |
338 | cd submodule && | |
339 | compare_head | |
340 | ) | |
341 | ' | |
342 | ||
32948425 | 343 | test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' |
ca2cedba | 344 | (cd super && |
32948425 | 345 | git config submodule.submodule.update checkout |
ca2cedba PH |
346 | ) && |
347 | (cd super/submodule && | |
348 | git reset --hard HEAD~1 | |
349 | ) && | |
350 | (cd super && | |
351 | (cd submodule && | |
352 | compare_head | |
353 | ) && | |
354 | git submodule update --rebase submodule && | |
355 | cd submodule && | |
356 | compare_head | |
357 | ) | |
358 | ' | |
359 | ||
42b49178 JH |
360 | test_expect_success 'submodule update - merge in .git/config' ' |
361 | (cd super && | |
362 | git config submodule.submodule.update merge | |
363 | ) && | |
364 | (cd super/submodule && | |
365 | git reset --hard HEAD~1 | |
366 | ) && | |
367 | (cd super && | |
368 | (cd submodule && | |
369 | compare_head | |
370 | ) && | |
371 | git submodule update submodule && | |
372 | cd submodule && | |
373 | compare_head | |
374 | ) | |
375 | ' | |
376 | ||
377 | test_expect_success 'submodule update - checkout in .git/config but --merge given' ' | |
378 | (cd super && | |
379 | git config submodule.submodule.update checkout | |
380 | ) && | |
381 | (cd super/submodule && | |
382 | git reset --hard HEAD~1 | |
383 | ) && | |
384 | (cd super && | |
385 | (cd submodule && | |
386 | compare_head | |
387 | ) && | |
388 | git submodule update --merge submodule && | |
389 | cd submodule && | |
390 | compare_head | |
391 | ) | |
392 | ' | |
393 | ||
32948425 | 394 | test_expect_success 'submodule update - checkout in .git/config' ' |
ca2cedba | 395 | (cd super && |
32948425 | 396 | git config submodule.submodule.update checkout |
ca2cedba PH |
397 | ) && |
398 | (cd super/submodule && | |
399 | git reset --hard HEAD^ | |
400 | ) && | |
401 | (cd super && | |
402 | (cd submodule && | |
403 | compare_head | |
404 | ) && | |
405 | git submodule update submodule && | |
406 | cd submodule && | |
407 | ! compare_head | |
408 | ) | |
409 | ' | |
410 | ||
6cb5728c CP |
411 | test_expect_success 'submodule update - command in .git/config' ' |
412 | (cd super && | |
413 | git config submodule.submodule.update "!git checkout" | |
414 | ) && | |
415 | (cd super/submodule && | |
416 | git reset --hard HEAD^ | |
417 | ) && | |
418 | (cd super && | |
419 | (cd submodule && | |
420 | compare_head | |
421 | ) && | |
422 | git submodule update submodule && | |
423 | cd submodule && | |
424 | ! compare_head | |
425 | ) | |
426 | ' | |
427 | ||
e904deb8 | 428 | test_expect_success 'submodule update - command in .gitmodules is rejected' ' |
83a17fa8 SB |
429 | test_when_finished "git -C super reset --hard HEAD^" && |
430 | git -C super config -f .gitmodules submodule.submodule.update "!false" && | |
431 | git -C super commit -a -m "add command to .gitmodules file" && | |
432 | git -C super/submodule reset --hard $submodulesha1^ && | |
e904deb8 | 433 | test_must_fail git -C super submodule update submodule |
83a17fa8 SB |
434 | ' |
435 | ||
bb92255e JN |
436 | test_expect_success 'fsck detects command in .gitmodules' ' |
437 | git init command-in-gitmodules && | |
438 | ( | |
439 | cd command-in-gitmodules && | |
440 | git submodule add ../submodule submodule && | |
441 | test_commit adding-submodule && | |
442 | ||
443 | git config -f .gitmodules submodule.submodule.update "!false" && | |
444 | git add .gitmodules && | |
445 | test_commit configuring-update && | |
446 | test_must_fail git fsck | |
447 | ) | |
83a17fa8 SB |
448 | ' |
449 | ||
b08238ac SB |
450 | cat << EOF >expect |
451 | Execution of 'false $submodulesha1' failed in submodule path 'submodule' | |
452 | EOF | |
453 | ||
6cb5728c CP |
454 | test_expect_success 'submodule update - command in .git/config catches failure' ' |
455 | (cd super && | |
456 | git config submodule.submodule.update "!false" | |
457 | ) && | |
458 | (cd super/submodule && | |
b08238ac | 459 | git reset --hard $submodulesha1^ |
6cb5728c CP |
460 | ) && |
461 | (cd super && | |
b08238ac SB |
462 | test_must_fail git submodule update submodule 2>../actual |
463 | ) && | |
1108cea7 | 464 | test_cmp actual expect |
b08238ac SB |
465 | ' |
466 | ||
467 | cat << EOF >expect | |
468 | Execution of 'false $submodulesha1' failed in submodule path '../submodule' | |
469 | EOF | |
470 | ||
471 | test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' ' | |
472 | (cd super && | |
473 | git config submodule.submodule.update "!false" | |
474 | ) && | |
475 | (cd super/submodule && | |
476 | git reset --hard $submodulesha1^ | |
477 | ) && | |
478 | (cd super && | |
479 | mkdir tmp && cd tmp && | |
480 | test_must_fail git submodule update ../submodule 2>../../actual | |
c1e06d11 | 481 | ) && |
1108cea7 | 482 | test_cmp actual expect |
c1e06d11 SB |
483 | ' |
484 | ||
e7b37caf | 485 | test_expect_success 'submodule update - command run for initial population of submodule' ' |
a4dded01 | 486 | cat >expect <<-EOF && |
e7b37caf | 487 | Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\'' |
a4dded01 | 488 | EOF |
e7b37caf | 489 | rm -rf super/submodule && |
a4dded01 | 490 | test_must_fail git -C super submodule update 2>actual && |
1108cea7 | 491 | test_cmp expect actual && |
e7b37caf SB |
492 | git -C super submodule update --checkout |
493 | ' | |
494 | ||
c1e06d11 SB |
495 | cat << EOF >expect |
496 | Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' | |
497 | Failed to recurse into submodule path '../super' | |
498 | EOF | |
499 | ||
500 | test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' ' | |
501 | (cd recursivesuper && | |
502 | git submodule update --remote super && | |
503 | git add super && | |
504 | git commit -m "update to latest to have more than one commit in submodules" | |
505 | ) && | |
506 | git -C recursivesuper/super config submodule.submodule.update "!false" && | |
507 | git -C recursivesuper/super/submodule reset --hard $submodulesha1^ && | |
508 | (cd recursivesuper && | |
509 | mkdir -p tmp && cd tmp && | |
510 | test_must_fail git submodule update --recursive ../super 2>../../actual | |
b08238ac | 511 | ) && |
1108cea7 | 512 | test_cmp actual expect |
6cb5728c CP |
513 | ' |
514 | ||
ac1fbbda | 515 | test_expect_success 'submodule init does not copy command into .git/config' ' |
e904deb8 JN |
516 | test_when_finished "git -C super update-index --force-remove submodule1" && |
517 | test_when_finished git config -f super/.gitmodules \ | |
518 | --remove-section submodule.submodule1 && | |
ac1fbbda | 519 | (cd super && |
65799fbc EN |
520 | git ls-files -s submodule >out && |
521 | H=$(cut -d" " -f2 out) && | |
ac1fbbda JH |
522 | mkdir submodule1 && |
523 | git update-index --add --cacheinfo 160000 $H submodule1 && | |
524 | git config -f .gitmodules submodule.submodule1.path submodule1 && | |
525 | git config -f .gitmodules submodule.submodule1.url ../submodule && | |
526 | git config -f .gitmodules submodule.submodule1.update !false && | |
e904deb8 JN |
527 | test_must_fail git submodule init submodule1 && |
528 | test_expect_code 1 git config submodule.submodule1.update >actual && | |
529 | test_must_be_empty actual | |
ac1fbbda JH |
530 | ) |
531 | ' | |
532 | ||
ca2cedba PH |
533 | test_expect_success 'submodule init picks up rebase' ' |
534 | (cd super && | |
c9c8c56e | 535 | git config -f .gitmodules submodule.rebasing.update rebase && |
ca2cedba | 536 | git submodule init rebasing && |
c9c8c56e | 537 | test "rebase" = "$(git config submodule.rebasing.update)" |
ca2cedba PH |
538 | ) |
539 | ' | |
540 | ||
42b49178 JH |
541 | test_expect_success 'submodule init picks up merge' ' |
542 | (cd super && | |
c9c8c56e | 543 | git config -f .gitmodules submodule.merging.update merge && |
42b49178 | 544 | git submodule init merging && |
c9c8c56e | 545 | test "merge" = "$(git config submodule.merging.update)" |
42b49178 JH |
546 | ) |
547 | ' | |
548 | ||
b200021e | 549 | test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' |
e7b37caf | 550 | test_config -C super submodule.submodule.update checkout && |
b200021e SO |
551 | (cd super && |
552 | rm -rf submodule && | |
553 | git submodule update submodule && | |
554 | git status -s submodule >expect && | |
555 | rm -rf submodule && | |
556 | git submodule update --merge submodule && | |
557 | git status -s submodule >actual && | |
558 | test_cmp expect actual | |
559 | ) | |
560 | ' | |
561 | ||
562 | test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' | |
e7b37caf | 563 | test_config -C super submodule.submodule.update checkout && |
b200021e SO |
564 | (cd super && |
565 | rm -rf submodule && | |
566 | git submodule update submodule && | |
567 | git status -s submodule >expect && | |
568 | rm -rf submodule && | |
569 | git submodule update --rebase submodule && | |
570 | git status -s submodule >actual && | |
571 | test_cmp expect actual | |
572 | ) | |
573 | ' | |
574 | ||
575 | test_expect_success 'submodule update ignores update=merge config for new submodules' ' | |
576 | (cd super && | |
577 | rm -rf submodule && | |
578 | git submodule update submodule && | |
579 | git status -s submodule >expect && | |
580 | rm -rf submodule && | |
581 | git config submodule.submodule.update merge && | |
582 | git submodule update submodule && | |
583 | git status -s submodule >actual && | |
584 | git config --unset submodule.submodule.update && | |
585 | test_cmp expect actual | |
586 | ) | |
587 | ' | |
588 | ||
589 | test_expect_success 'submodule update ignores update=rebase config for new submodules' ' | |
590 | (cd super && | |
591 | rm -rf submodule && | |
592 | git submodule update submodule && | |
593 | git status -s submodule >expect && | |
594 | rm -rf submodule && | |
595 | git config submodule.submodule.update rebase && | |
596 | git submodule update submodule && | |
597 | git status -s submodule >actual && | |
598 | git config --unset submodule.submodule.update && | |
599 | test_cmp expect actual | |
600 | ) | |
601 | ' | |
602 | ||
322bb6e1 HV |
603 | test_expect_success 'submodule init picks up update=none' ' |
604 | (cd super && | |
605 | git config -f .gitmodules submodule.none.update none && | |
606 | git submodule init none && | |
607 | test "none" = "$(git config submodule.none.update)" | |
608 | ) | |
609 | ' | |
610 | ||
611 | test_expect_success 'submodule update - update=none in .git/config' ' | |
612 | (cd super && | |
613 | git config submodule.submodule.update none && | |
614 | (cd submodule && | |
01dc8133 | 615 | git checkout main && |
322bb6e1 HV |
616 | compare_head |
617 | ) && | |
65799fbc EN |
618 | git diff --name-only >out && |
619 | grep ^submodule$ out && | |
322bb6e1 | 620 | git submodule update && |
65799fbc EN |
621 | git diff --name-only >out && |
622 | grep ^submodule$ out && | |
322bb6e1 HV |
623 | (cd submodule && |
624 | compare_head | |
625 | ) && | |
626 | git config --unset submodule.submodule.update && | |
627 | git submodule update submodule | |
628 | ) | |
629 | ' | |
630 | ||
631 | test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' | |
632 | (cd super && | |
633 | git config submodule.submodule.update none && | |
634 | (cd submodule && | |
01dc8133 | 635 | git checkout main && |
322bb6e1 HV |
636 | compare_head |
637 | ) && | |
65799fbc EN |
638 | git diff --name-only >out && |
639 | grep ^submodule$ out && | |
322bb6e1 | 640 | git submodule update --checkout && |
602813cf EN |
641 | git diff --name-only >out && |
642 | ! grep ^submodule$ out && | |
322bb6e1 | 643 | (cd submodule && |
9fd1080a | 644 | ! compare_head |
322bb6e1 HV |
645 | ) && |
646 | git config --unset submodule.submodule.update | |
647 | ) | |
648 | ' | |
649 | ||
650 | test_expect_success 'submodule update --init skips submodule with update=none' ' | |
651 | (cd super && | |
652 | git add .gitmodules && | |
653 | git commit -m ".gitmodules" | |
654 | ) && | |
655 | git clone super cloned && | |
656 | (cd cloned && | |
657 | git submodule update --init && | |
7e9055bb EN |
658 | test_path_exists submodule/.git && |
659 | test_path_is_missing none/.git | |
322bb6e1 HV |
660 | ) |
661 | ' | |
662 | ||
15ffb7cd FG |
663 | test_expect_success 'submodule update continues after checkout error' ' |
664 | (cd super && | |
665 | git reset --hard HEAD && | |
666 | git submodule add ../submodule submodule2 && | |
667 | git submodule init && | |
668 | git commit -am "new_submodule" && | |
669 | (cd submodule2 && | |
ad6a599c | 670 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
671 | ) && |
672 | (cd submodule && | |
673 | test_commit "update_submodule" file | |
674 | ) && | |
675 | (cd submodule2 && | |
676 | test_commit "update_submodule2" file | |
677 | ) && | |
678 | git add submodule && | |
679 | git add submodule2 && | |
680 | git commit -m "two_new_submodule_commits" && | |
681 | (cd submodule && | |
682 | echo "" > file | |
683 | ) && | |
684 | git checkout HEAD^ && | |
685 | test_must_fail git submodule update && | |
686 | (cd submodule2 && | |
ad6a599c | 687 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
688 | ) && |
689 | test_cmp expect actual | |
690 | ) | |
691 | ' | |
692 | test_expect_success 'submodule update continues after recursive checkout error' ' | |
693 | (cd super && | |
694 | git reset --hard HEAD && | |
01dc8133 | 695 | git checkout main && |
15ffb7cd FG |
696 | git submodule update && |
697 | (cd submodule && | |
698 | git submodule add ../submodule subsubmodule && | |
699 | git submodule init && | |
700 | git commit -m "new_subsubmodule" | |
701 | ) && | |
702 | git add submodule && | |
703 | git commit -m "update_submodule" && | |
704 | (cd submodule && | |
705 | (cd subsubmodule && | |
706 | test_commit "update_subsubmodule" file | |
707 | ) && | |
708 | git add subsubmodule && | |
709 | test_commit "update_submodule_again" file && | |
710 | (cd subsubmodule && | |
711 | test_commit "update_subsubmodule_again" file | |
712 | ) && | |
713 | test_commit "update_submodule_again_again" file | |
714 | ) && | |
715 | (cd submodule2 && | |
ad6a599c | 716 | git rev-parse --verify HEAD >../expect && |
15ffb7cd FG |
717 | test_commit "update_submodule2_again" file |
718 | ) && | |
719 | git add submodule && | |
720 | git add submodule2 && | |
721 | git commit -m "new_commits" && | |
722 | git checkout HEAD^ && | |
723 | (cd submodule && | |
724 | git checkout HEAD^ && | |
725 | (cd subsubmodule && | |
726 | echo "" > file | |
727 | ) | |
728 | ) && | |
729 | test_must_fail git submodule update --recursive && | |
730 | (cd submodule2 && | |
ad6a599c | 731 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
732 | ) && |
733 | test_cmp expect actual | |
734 | ) | |
735 | ' | |
736 | ||
737 | test_expect_success 'submodule update exit immediately in case of merge conflict' ' | |
738 | (cd super && | |
01dc8133 | 739 | git checkout main && |
15ffb7cd FG |
740 | git reset --hard HEAD && |
741 | (cd submodule && | |
742 | (cd subsubmodule && | |
743 | git reset --hard HEAD | |
744 | ) | |
745 | ) && | |
746 | git submodule update --recursive && | |
747 | (cd submodule && | |
748 | test_commit "update_submodule_2" file | |
749 | ) && | |
750 | (cd submodule2 && | |
751 | test_commit "update_submodule2_2" file | |
752 | ) && | |
753 | git add submodule && | |
754 | git add submodule2 && | |
755 | git commit -m "two_new_submodule_commits" && | |
756 | (cd submodule && | |
01dc8133 | 757 | git checkout main && |
15ffb7cd FG |
758 | test_commit "conflict" file && |
759 | echo "conflict" > file | |
760 | ) && | |
761 | git checkout HEAD^ && | |
762 | (cd submodule2 && | |
ad6a599c | 763 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
764 | ) && |
765 | git config submodule.submodule.update merge && | |
766 | test_must_fail git submodule update && | |
767 | (cd submodule2 && | |
ad6a599c | 768 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
769 | ) && |
770 | test_cmp expect actual | |
771 | ) | |
772 | ' | |
501770e1 | 773 | |
15ffb7cd FG |
774 | test_expect_success 'submodule update exit immediately after recursive rebase error' ' |
775 | (cd super && | |
01dc8133 | 776 | git checkout main && |
15ffb7cd FG |
777 | git reset --hard HEAD && |
778 | (cd submodule && | |
779 | git reset --hard HEAD && | |
780 | git submodule update --recursive | |
781 | ) && | |
782 | (cd submodule && | |
783 | test_commit "update_submodule_3" file | |
784 | ) && | |
785 | (cd submodule2 && | |
786 | test_commit "update_submodule2_3" file | |
787 | ) && | |
788 | git add submodule && | |
789 | git add submodule2 && | |
790 | git commit -m "two_new_submodule_commits" && | |
791 | (cd submodule && | |
01dc8133 | 792 | git checkout main && |
15ffb7cd FG |
793 | test_commit "conflict2" file && |
794 | echo "conflict" > file | |
795 | ) && | |
796 | git checkout HEAD^ && | |
797 | (cd submodule2 && | |
ad6a599c | 798 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
799 | ) && |
800 | git config submodule.submodule.update rebase && | |
801 | test_must_fail git submodule update && | |
802 | (cd submodule2 && | |
ad6a599c | 803 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
804 | ) && |
805 | test_cmp expect actual | |
806 | ) | |
807 | ' | |
501770e1 FG |
808 | |
809 | test_expect_success 'add different submodules to the same path' ' | |
810 | (cd super && | |
811 | git submodule add ../submodule s1 && | |
812 | test_must_fail git submodule add ../merging s1 | |
813 | ) | |
814 | ' | |
815 | ||
816 | test_expect_success 'submodule add places git-dir in superprojects git-dir' ' | |
817 | (cd super && | |
818 | mkdir deeper && | |
819 | git submodule add ../submodule deeper/submodule && | |
820 | (cd deeper/submodule && | |
821 | git log > ../../expected | |
822 | ) && | |
823 | (cd .git/modules/deeper/submodule && | |
824 | git log > ../../../../actual | |
825 | ) && | |
dcbaa0b3 | 826 | test_cmp expected actual |
501770e1 FG |
827 | ) |
828 | ' | |
829 | ||
830 | test_expect_success 'submodule update places git-dir in superprojects git-dir' ' | |
831 | (cd super && | |
832 | git commit -m "added submodule" | |
833 | ) && | |
834 | git clone super super2 && | |
835 | (cd super2 && | |
836 | git submodule init deeper/submodule && | |
837 | git submodule update && | |
838 | (cd deeper/submodule && | |
839 | git log > ../../expected | |
840 | ) && | |
841 | (cd .git/modules/deeper/submodule && | |
842 | git log > ../../../../actual | |
843 | ) && | |
dcbaa0b3 | 844 | test_cmp expected actual |
501770e1 FG |
845 | ) |
846 | ' | |
847 | ||
848 | test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' | |
849 | (cd super2 && | |
850 | (cd deeper/submodule && | |
851 | git submodule add ../submodule subsubmodule && | |
852 | (cd subsubmodule && | |
853 | git log > ../../../expected | |
854 | ) && | |
855 | git commit -m "added subsubmodule" && | |
ae74f7d2 | 856 | git push origin : |
501770e1 FG |
857 | ) && |
858 | (cd .git/modules/deeper/submodule/modules/subsubmodule && | |
859 | git log > ../../../../../actual | |
860 | ) && | |
861 | git add deeper/submodule && | |
862 | git commit -m "update submodule" && | |
ae74f7d2 | 863 | git push origin : && |
dcbaa0b3 | 864 | test_cmp expected actual |
501770e1 FG |
865 | ) |
866 | ' | |
867 | ||
868 | test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' | |
869 | mkdir super_update_r && | |
870 | (cd super_update_r && | |
871 | git init --bare | |
872 | ) && | |
873 | mkdir subsuper_update_r && | |
874 | (cd subsuper_update_r && | |
875 | git init --bare | |
876 | ) && | |
877 | mkdir subsubsuper_update_r && | |
878 | (cd subsubsuper_update_r && | |
879 | git init --bare | |
880 | ) && | |
881 | git clone subsubsuper_update_r subsubsuper_update_r2 && | |
882 | (cd subsubsuper_update_r2 && | |
883 | test_commit "update_subsubsuper" file && | |
01dc8133 | 884 | git push origin main |
501770e1 FG |
885 | ) && |
886 | git clone subsuper_update_r subsuper_update_r2 && | |
887 | (cd subsuper_update_r2 && | |
888 | test_commit "update_subsuper" file && | |
889 | git submodule add ../subsubsuper_update_r subsubmodule && | |
890 | git commit -am "subsubmodule" && | |
01dc8133 | 891 | git push origin main |
501770e1 FG |
892 | ) && |
893 | git clone super_update_r super_update_r2 && | |
894 | (cd super_update_r2 && | |
895 | test_commit "update_super" file && | |
896 | git submodule add ../subsuper_update_r submodule && | |
897 | git commit -am "submodule" && | |
01dc8133 | 898 | git push origin main |
501770e1 FG |
899 | ) && |
900 | rm -rf super_update_r2 && | |
901 | git clone super_update_r super_update_r2 && | |
902 | (cd super_update_r2 && | |
75bf5e60 | 903 | git submodule update --init --recursive >actual && |
d851ffb9 | 904 | test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual && |
501770e1 FG |
905 | (cd submodule/subsubmodule && |
906 | git log > ../../expected | |
907 | ) && | |
e974e06d | 908 | (cd .git/modules/submodule/modules/subsubmodule && |
501770e1 | 909 | git log > ../../../../../actual |
e974e06d | 910 | ) && |
dcbaa0b3 | 911 | test_cmp expected actual |
501770e1 FG |
912 | ) |
913 | ' | |
914 | ||
1017c1ab JL |
915 | test_expect_success 'submodule add properly re-creates deeper level submodules' ' |
916 | (cd super && | |
01dc8133 | 917 | git reset --hard main && |
1017c1ab | 918 | rm -rf deeper/ && |
4b7c286e | 919 | git submodule add --force ../submodule deeper/submodule |
1017c1ab JL |
920 | ) |
921 | ' | |
922 | ||
69c30517 JL |
923 | test_expect_success 'submodule update properly revives a moved submodule' ' |
924 | (cd super && | |
b397ea48 | 925 | H=$(git rev-parse --short HEAD) && |
69c30517 | 926 | git commit -am "pre move" && |
b397ea48 | 927 | H2=$(git rev-parse --short HEAD) && |
65799fbc EN |
928 | git status >out && |
929 | sed "s/$H/XXX/" out >expect && | |
e974e06d | 930 | H=$(cd submodule2 && git rev-parse HEAD) && |
69c30517 JL |
931 | git rm --cached submodule2 && |
932 | rm -rf submodule2 && | |
933 | mkdir -p "moved/sub module" && | |
934 | git update-index --add --cacheinfo 160000 $H "moved/sub module" && | |
8de19d6b | 935 | git config -f .gitmodules submodule.submodule2.path "moved/sub module" && |
69c30517 JL |
936 | git commit -am "post move" && |
937 | git submodule update && | |
65799fbc EN |
938 | git status > out && |
939 | sed "s/$H2/XXX/" out >actual && | |
69c30517 JL |
940 | test_cmp expect actual |
941 | ) | |
942 | ' | |
943 | ||
6eafa6d0 JL |
944 | test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' |
945 | mkdir -p linked/dir && | |
946 | ln -s linked/dir linkto && | |
275cd184 FG |
947 | (cd linkto && |
948 | git clone "$TRASH_DIRECTORY"/super_update_r2 super && | |
949 | (cd super && | |
950 | git submodule update --init --recursive | |
951 | ) | |
6eafa6d0 JL |
952 | ) |
953 | ' | |
954 | ||
275cd184 | 955 | test_expect_success 'submodule update clone shallow submodule' ' |
d4470c5a | 956 | test_when_finished "rm -rf super3" && |
65799fbc | 957 | first=$(git -C cloned rev-parse HEAD:submodule) && |
d4470c5a | 958 | second=$(git -C submodule rev-parse HEAD) && |
967d7f89 | 959 | commit_count=$(git -C submodule rev-list --count $first^..$second) && |
275cd184 | 960 | git clone cloned super3 && |
99094a7a | 961 | pwd=$(pwd) && |
d4470c5a SB |
962 | ( |
963 | cd super3 && | |
964 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && | |
965 | mv -f .gitmodules.tmp .gitmodules && | |
966 | git submodule update --init --depth=$commit_count && | |
65799fbc EN |
967 | git -C submodule log --oneline >out && |
968 | test_line_count = 1 out | |
d4470c5a | 969 | ) |
36141282 JL |
970 | ' |
971 | ||
6cbf454a SB |
972 | test_expect_success 'submodule update clone shallow submodule outside of depth' ' |
973 | test_when_finished "rm -rf super3" && | |
974 | git clone cloned super3 && | |
975 | pwd=$(pwd) && | |
976 | ( | |
977 | cd super3 && | |
978 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && | |
979 | mv -f .gitmodules.tmp .gitmodules && | |
ab0c5f50 JT |
980 | # Some protocol versions (e.g. 2) support fetching |
981 | # unadvertised objects, so restrict this test to v0. | |
8a1b0978 | 982 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
ab0c5f50 | 983 | git submodule update --init --depth=1 2>actual && |
6cbf454a SB |
984 | test_i18ngrep "Direct fetching of that commit failed." actual && |
985 | git -C ../submodule config uploadpack.allowReachableSHA1InWant true && | |
986 | git submodule update --init --depth=1 >actual && | |
65799fbc EN |
987 | git -C submodule log --oneline >out && |
988 | test_line_count = 1 out | |
6cbf454a SB |
989 | ) |
990 | ' | |
991 | ||
36141282 JL |
992 | test_expect_success 'submodule update --recursive drops module name before recursing' ' |
993 | (cd super2 && | |
994 | (cd deeper/submodule/subsubmodule && | |
995 | git checkout HEAD^ | |
996 | ) && | |
997 | git submodule update --recursive deeper/submodule >actual && | |
998 | test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual | |
275cd184 FG |
999 | ) |
1000 | ' | |
2335b870 SB |
1001 | |
1002 | test_expect_success 'submodule update can be run in parallel' ' | |
1003 | (cd super2 && | |
1004 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 && | |
1005 | grep "7 tasks" trace.out && | |
1006 | git config submodule.fetchJobs 8 && | |
1007 | GIT_TRACE=$(pwd)/trace.out git submodule update && | |
1008 | grep "8 tasks" trace.out && | |
1009 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 && | |
1010 | grep "9 tasks" trace.out | |
1011 | ) | |
1012 | ' | |
72290d6a SB |
1013 | |
1014 | test_expect_success 'git clone passes the parallel jobs config on to submodules' ' | |
1015 | test_when_finished "rm -rf super4" && | |
1016 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 && | |
1017 | grep "7 tasks" trace.out && | |
1018 | rm -rf super4 && | |
1019 | git config --global submodule.fetchJobs 8 && | |
1020 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 && | |
1021 | grep "8 tasks" trace.out && | |
1022 | rm -rf super4 && | |
1023 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 && | |
1024 | grep "9 tasks" trace.out && | |
1025 | rm -rf super4 | |
1026 | ' | |
1027 | ||
3ad0401e TD |
1028 | test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ' |
1029 | (cd super && | |
1030 | test_commit -C rebasing message && | |
1031 | git submodule update --rebase --quiet >out 2>err && | |
1032 | test_must_be_empty out && | |
1033 | test_must_be_empty err && | |
1034 | git submodule update --rebase -v >out 2>err && | |
1035 | test_file_not_empty out && | |
1036 | test_must_be_empty err | |
1037 | ) | |
1038 | ' | |
1039 | ||
ca2cedba | 1040 | test_done |