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