]>
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 | ||
4d7bc52b SB |
212 | test_expect_success 'submodule update --remote should fetch upstream changes with .' ' |
213 | ( | |
214 | cd super && | |
215 | git config -f .gitmodules submodule."submodule".branch "." && | |
216 | git add .gitmodules && | |
217 | git commit -m "submodules: update from the respective superproject branch" | |
218 | ) && | |
219 | ( | |
220 | cd submodule && | |
221 | echo line4a >> file && | |
222 | git add file && | |
223 | test_tick && | |
224 | git commit -m "upstream line4a" && | |
225 | git checkout -b test-branch && | |
226 | test_commit on-test-branch | |
227 | ) && | |
228 | ( | |
229 | cd super && | |
230 | git submodule update --remote --force submodule && | |
231 | git -C submodule log -1 --oneline >actual | |
232 | git -C ../submodule log -1 --oneline master >expect | |
233 | test_cmp expect actual && | |
234 | git checkout -b test-branch && | |
235 | git submodule update --remote --force submodule && | |
236 | git -C submodule log -1 --oneline >actual | |
237 | git -C ../submodule log -1 --oneline test-branch >expect | |
238 | test_cmp expect actual && | |
239 | git checkout master && | |
240 | git branch -d test-branch && | |
241 | git reset --hard HEAD^ | |
242 | ) | |
243 | ' | |
244 | ||
06b1abb5 TK |
245 | test_expect_success 'local config should override .gitmodules branch' ' |
246 | (cd submodule && | |
4d7bc52b | 247 | git checkout test-branch && |
06b1abb5 TK |
248 | echo line5 >> file && |
249 | git add file && | |
250 | test_tick && | |
251 | git commit -m "upstream line5" && | |
252 | git checkout master | |
253 | ) && | |
254 | (cd super && | |
255 | git config submodule.submodule.branch test-branch && | |
256 | git submodule update --remote --force submodule && | |
257 | cd submodule && | |
258 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)" | |
259 | ) | |
260 | ' | |
261 | ||
ca2cedba PH |
262 | test_expect_success 'submodule update --rebase staying on master' ' |
263 | (cd super/submodule && | |
264 | git checkout master | |
265 | ) && | |
266 | (cd super && | |
267 | (cd submodule && | |
268 | compare_head | |
269 | ) && | |
270 | git submodule update --rebase submodule && | |
271 | cd submodule && | |
272 | compare_head | |
273 | ) | |
274 | ' | |
275 | ||
42b49178 JH |
276 | test_expect_success 'submodule update --merge staying on master' ' |
277 | (cd super/submodule && | |
278 | git reset --hard HEAD~1 | |
279 | ) && | |
280 | (cd super && | |
281 | (cd submodule && | |
282 | compare_head | |
283 | ) && | |
284 | git submodule update --merge submodule && | |
285 | cd submodule && | |
286 | compare_head | |
287 | ) | |
288 | ' | |
289 | ||
32948425 | 290 | test_expect_success 'submodule update - rebase in .git/config' ' |
ca2cedba | 291 | (cd super && |
32948425 | 292 | git config submodule.submodule.update rebase |
ca2cedba PH |
293 | ) && |
294 | (cd super/submodule && | |
295 | git reset --hard HEAD~1 | |
296 | ) && | |
297 | (cd super && | |
298 | (cd submodule && | |
299 | compare_head | |
300 | ) && | |
301 | git submodule update submodule && | |
302 | cd submodule && | |
303 | compare_head | |
304 | ) | |
305 | ' | |
306 | ||
32948425 | 307 | test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' |
ca2cedba | 308 | (cd super && |
32948425 | 309 | git config submodule.submodule.update checkout |
ca2cedba PH |
310 | ) && |
311 | (cd super/submodule && | |
312 | git reset --hard HEAD~1 | |
313 | ) && | |
314 | (cd super && | |
315 | (cd submodule && | |
316 | compare_head | |
317 | ) && | |
318 | git submodule update --rebase submodule && | |
319 | cd submodule && | |
320 | compare_head | |
321 | ) | |
322 | ' | |
323 | ||
42b49178 JH |
324 | test_expect_success 'submodule update - merge in .git/config' ' |
325 | (cd super && | |
326 | git config submodule.submodule.update merge | |
327 | ) && | |
328 | (cd super/submodule && | |
329 | git reset --hard HEAD~1 | |
330 | ) && | |
331 | (cd super && | |
332 | (cd submodule && | |
333 | compare_head | |
334 | ) && | |
335 | git submodule update submodule && | |
336 | cd submodule && | |
337 | compare_head | |
338 | ) | |
339 | ' | |
340 | ||
341 | test_expect_success 'submodule update - checkout in .git/config but --merge given' ' | |
342 | (cd super && | |
343 | git config submodule.submodule.update checkout | |
344 | ) && | |
345 | (cd super/submodule && | |
346 | git reset --hard HEAD~1 | |
347 | ) && | |
348 | (cd super && | |
349 | (cd submodule && | |
350 | compare_head | |
351 | ) && | |
352 | git submodule update --merge submodule && | |
353 | cd submodule && | |
354 | compare_head | |
355 | ) | |
356 | ' | |
357 | ||
32948425 | 358 | test_expect_success 'submodule update - checkout in .git/config' ' |
ca2cedba | 359 | (cd super && |
32948425 | 360 | git config submodule.submodule.update checkout |
ca2cedba PH |
361 | ) && |
362 | (cd super/submodule && | |
363 | git reset --hard HEAD^ | |
364 | ) && | |
365 | (cd super && | |
366 | (cd submodule && | |
367 | compare_head | |
368 | ) && | |
369 | git submodule update submodule && | |
370 | cd submodule && | |
371 | ! compare_head | |
372 | ) | |
373 | ' | |
374 | ||
6cb5728c CP |
375 | test_expect_success 'submodule update - command in .git/config' ' |
376 | (cd super && | |
377 | git config submodule.submodule.update "!git checkout" | |
378 | ) && | |
379 | (cd super/submodule && | |
380 | git reset --hard HEAD^ | |
381 | ) && | |
382 | (cd super && | |
383 | (cd submodule && | |
384 | compare_head | |
385 | ) && | |
386 | git submodule update submodule && | |
387 | cd submodule && | |
388 | ! compare_head | |
389 | ) | |
390 | ' | |
391 | ||
b08238ac SB |
392 | cat << EOF >expect |
393 | Execution of 'false $submodulesha1' failed in submodule path 'submodule' | |
394 | EOF | |
395 | ||
6cb5728c CP |
396 | test_expect_success 'submodule update - command in .git/config catches failure' ' |
397 | (cd super && | |
398 | git config submodule.submodule.update "!false" | |
399 | ) && | |
400 | (cd super/submodule && | |
b08238ac | 401 | git reset --hard $submodulesha1^ |
6cb5728c CP |
402 | ) && |
403 | (cd super && | |
b08238ac SB |
404 | test_must_fail git submodule update submodule 2>../actual |
405 | ) && | |
1edbaac3 | 406 | test_i18ncmp actual expect |
b08238ac SB |
407 | ' |
408 | ||
409 | cat << EOF >expect | |
410 | Execution of 'false $submodulesha1' failed in submodule path '../submodule' | |
411 | EOF | |
412 | ||
413 | test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' ' | |
414 | (cd super && | |
415 | git config submodule.submodule.update "!false" | |
416 | ) && | |
417 | (cd super/submodule && | |
418 | git reset --hard $submodulesha1^ | |
419 | ) && | |
420 | (cd super && | |
421 | mkdir tmp && cd tmp && | |
422 | test_must_fail git submodule update ../submodule 2>../../actual | |
c1e06d11 | 423 | ) && |
1edbaac3 | 424 | test_i18ncmp actual expect |
c1e06d11 SB |
425 | ' |
426 | ||
427 | cat << EOF >expect | |
428 | Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' | |
429 | Failed to recurse into submodule path '../super' | |
430 | EOF | |
431 | ||
432 | test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' ' | |
433 | (cd recursivesuper && | |
434 | git submodule update --remote super && | |
435 | git add super && | |
436 | git commit -m "update to latest to have more than one commit in submodules" | |
437 | ) && | |
438 | git -C recursivesuper/super config submodule.submodule.update "!false" && | |
439 | git -C recursivesuper/super/submodule reset --hard $submodulesha1^ && | |
440 | (cd recursivesuper && | |
441 | mkdir -p tmp && cd tmp && | |
442 | test_must_fail git submodule update --recursive ../super 2>../../actual | |
b08238ac | 443 | ) && |
1edbaac3 | 444 | test_i18ncmp actual expect |
6cb5728c CP |
445 | ' |
446 | ||
ac1fbbda JH |
447 | test_expect_success 'submodule init does not copy command into .git/config' ' |
448 | (cd super && | |
449 | H=$(git ls-files -s submodule | cut -d" " -f2) && | |
450 | mkdir submodule1 && | |
451 | git update-index --add --cacheinfo 160000 $H submodule1 && | |
452 | git config -f .gitmodules submodule.submodule1.path submodule1 && | |
453 | git config -f .gitmodules submodule.submodule1.url ../submodule && | |
454 | git config -f .gitmodules submodule.submodule1.update !false && | |
455 | git submodule init submodule1 && | |
456 | echo "none" >expect && | |
457 | git config submodule.submodule1.update >actual && | |
458 | test_cmp expect actual | |
459 | ) | |
460 | ' | |
461 | ||
ca2cedba PH |
462 | test_expect_success 'submodule init picks up rebase' ' |
463 | (cd super && | |
c9c8c56e | 464 | git config -f .gitmodules submodule.rebasing.update rebase && |
ca2cedba | 465 | git submodule init rebasing && |
c9c8c56e | 466 | test "rebase" = "$(git config submodule.rebasing.update)" |
ca2cedba PH |
467 | ) |
468 | ' | |
469 | ||
42b49178 JH |
470 | test_expect_success 'submodule init picks up merge' ' |
471 | (cd super && | |
c9c8c56e | 472 | git config -f .gitmodules submodule.merging.update merge && |
42b49178 | 473 | git submodule init merging && |
c9c8c56e | 474 | test "merge" = "$(git config submodule.merging.update)" |
42b49178 JH |
475 | ) |
476 | ' | |
477 | ||
b200021e SO |
478 | test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' |
479 | (cd super && | |
480 | rm -rf submodule && | |
481 | git submodule update submodule && | |
482 | git status -s submodule >expect && | |
483 | rm -rf submodule && | |
484 | git submodule update --merge submodule && | |
485 | git status -s submodule >actual && | |
486 | test_cmp expect actual | |
487 | ) | |
488 | ' | |
489 | ||
490 | test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' | |
491 | (cd super && | |
492 | rm -rf submodule && | |
493 | git submodule update submodule && | |
494 | git status -s submodule >expect && | |
495 | rm -rf submodule && | |
496 | git submodule update --rebase submodule && | |
497 | git status -s submodule >actual && | |
498 | test_cmp expect actual | |
499 | ) | |
500 | ' | |
501 | ||
502 | test_expect_success 'submodule update ignores update=merge config for new submodules' ' | |
503 | (cd super && | |
504 | rm -rf submodule && | |
505 | git submodule update submodule && | |
506 | git status -s submodule >expect && | |
507 | rm -rf submodule && | |
508 | git config submodule.submodule.update merge && | |
509 | git submodule update submodule && | |
510 | git status -s submodule >actual && | |
511 | git config --unset submodule.submodule.update && | |
512 | test_cmp expect actual | |
513 | ) | |
514 | ' | |
515 | ||
516 | test_expect_success 'submodule update ignores update=rebase config for new submodules' ' | |
517 | (cd super && | |
518 | rm -rf submodule && | |
519 | git submodule update submodule && | |
520 | git status -s submodule >expect && | |
521 | rm -rf submodule && | |
522 | git config submodule.submodule.update rebase && | |
523 | git submodule update submodule && | |
524 | git status -s submodule >actual && | |
525 | git config --unset submodule.submodule.update && | |
526 | test_cmp expect actual | |
527 | ) | |
528 | ' | |
529 | ||
322bb6e1 HV |
530 | test_expect_success 'submodule init picks up update=none' ' |
531 | (cd super && | |
532 | git config -f .gitmodules submodule.none.update none && | |
533 | git submodule init none && | |
534 | test "none" = "$(git config submodule.none.update)" | |
535 | ) | |
536 | ' | |
537 | ||
538 | test_expect_success 'submodule update - update=none in .git/config' ' | |
539 | (cd super && | |
540 | git config submodule.submodule.update none && | |
541 | (cd submodule && | |
542 | git checkout master && | |
543 | compare_head | |
544 | ) && | |
545 | git diff --raw | grep " submodule" && | |
546 | git submodule update && | |
547 | git diff --raw | grep " submodule" && | |
548 | (cd submodule && | |
549 | compare_head | |
550 | ) && | |
551 | git config --unset submodule.submodule.update && | |
552 | git submodule update submodule | |
553 | ) | |
554 | ' | |
555 | ||
556 | test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' | |
557 | (cd super && | |
558 | git config submodule.submodule.update none && | |
559 | (cd submodule && | |
560 | git checkout master && | |
561 | compare_head | |
562 | ) && | |
563 | git diff --raw | grep " submodule" && | |
564 | git submodule update --checkout && | |
565 | test_must_fail git diff --raw \| grep " submodule" && | |
566 | (cd submodule && | |
567 | test_must_fail compare_head | |
568 | ) && | |
569 | git config --unset submodule.submodule.update | |
570 | ) | |
571 | ' | |
572 | ||
573 | test_expect_success 'submodule update --init skips submodule with update=none' ' | |
574 | (cd super && | |
575 | git add .gitmodules && | |
576 | git commit -m ".gitmodules" | |
577 | ) && | |
578 | git clone super cloned && | |
579 | (cd cloned && | |
580 | git submodule update --init && | |
581 | test -e submodule/.git && | |
582 | test_must_fail test -e none/.git | |
583 | ) | |
584 | ' | |
585 | ||
15ffb7cd FG |
586 | test_expect_success 'submodule update continues after checkout error' ' |
587 | (cd super && | |
588 | git reset --hard HEAD && | |
589 | git submodule add ../submodule submodule2 && | |
590 | git submodule init && | |
591 | git commit -am "new_submodule" && | |
592 | (cd submodule2 && | |
ad6a599c | 593 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
594 | ) && |
595 | (cd submodule && | |
596 | test_commit "update_submodule" file | |
597 | ) && | |
598 | (cd submodule2 && | |
599 | test_commit "update_submodule2" file | |
600 | ) && | |
601 | git add submodule && | |
602 | git add submodule2 && | |
603 | git commit -m "two_new_submodule_commits" && | |
604 | (cd submodule && | |
605 | echo "" > file | |
606 | ) && | |
607 | git checkout HEAD^ && | |
608 | test_must_fail git submodule update && | |
609 | (cd submodule2 && | |
ad6a599c | 610 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
611 | ) && |
612 | test_cmp expect actual | |
613 | ) | |
614 | ' | |
615 | test_expect_success 'submodule update continues after recursive checkout error' ' | |
616 | (cd super && | |
617 | git reset --hard HEAD && | |
618 | git checkout master && | |
619 | git submodule update && | |
620 | (cd submodule && | |
621 | git submodule add ../submodule subsubmodule && | |
622 | git submodule init && | |
623 | git commit -m "new_subsubmodule" | |
624 | ) && | |
625 | git add submodule && | |
626 | git commit -m "update_submodule" && | |
627 | (cd submodule && | |
628 | (cd subsubmodule && | |
629 | test_commit "update_subsubmodule" file | |
630 | ) && | |
631 | git add subsubmodule && | |
632 | test_commit "update_submodule_again" file && | |
633 | (cd subsubmodule && | |
634 | test_commit "update_subsubmodule_again" file | |
635 | ) && | |
636 | test_commit "update_submodule_again_again" file | |
637 | ) && | |
638 | (cd submodule2 && | |
ad6a599c | 639 | git rev-parse --verify HEAD >../expect && |
15ffb7cd FG |
640 | test_commit "update_submodule2_again" file |
641 | ) && | |
642 | git add submodule && | |
643 | git add submodule2 && | |
644 | git commit -m "new_commits" && | |
645 | git checkout HEAD^ && | |
646 | (cd submodule && | |
647 | git checkout HEAD^ && | |
648 | (cd subsubmodule && | |
649 | echo "" > file | |
650 | ) | |
651 | ) && | |
652 | test_must_fail git submodule update --recursive && | |
653 | (cd submodule2 && | |
ad6a599c | 654 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
655 | ) && |
656 | test_cmp expect actual | |
657 | ) | |
658 | ' | |
659 | ||
660 | test_expect_success 'submodule update exit immediately in case of merge conflict' ' | |
661 | (cd super && | |
662 | git checkout master && | |
663 | git reset --hard HEAD && | |
664 | (cd submodule && | |
665 | (cd subsubmodule && | |
666 | git reset --hard HEAD | |
667 | ) | |
668 | ) && | |
669 | git submodule update --recursive && | |
670 | (cd submodule && | |
671 | test_commit "update_submodule_2" file | |
672 | ) && | |
673 | (cd submodule2 && | |
674 | test_commit "update_submodule2_2" file | |
675 | ) && | |
676 | git add submodule && | |
677 | git add submodule2 && | |
678 | git commit -m "two_new_submodule_commits" && | |
679 | (cd submodule && | |
680 | git checkout master && | |
681 | test_commit "conflict" file && | |
682 | echo "conflict" > file | |
683 | ) && | |
684 | git checkout HEAD^ && | |
685 | (cd submodule2 && | |
ad6a599c | 686 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
687 | ) && |
688 | git config submodule.submodule.update merge && | |
689 | test_must_fail git submodule update && | |
690 | (cd submodule2 && | |
ad6a599c | 691 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
692 | ) && |
693 | test_cmp expect actual | |
694 | ) | |
695 | ' | |
501770e1 | 696 | |
15ffb7cd FG |
697 | test_expect_success 'submodule update exit immediately after recursive rebase error' ' |
698 | (cd super && | |
699 | git checkout master && | |
700 | git reset --hard HEAD && | |
701 | (cd submodule && | |
702 | git reset --hard HEAD && | |
703 | git submodule update --recursive | |
704 | ) && | |
705 | (cd submodule && | |
706 | test_commit "update_submodule_3" file | |
707 | ) && | |
708 | (cd submodule2 && | |
709 | test_commit "update_submodule2_3" file | |
710 | ) && | |
711 | git add submodule && | |
712 | git add submodule2 && | |
713 | git commit -m "two_new_submodule_commits" && | |
714 | (cd submodule && | |
715 | git checkout master && | |
716 | test_commit "conflict2" file && | |
717 | echo "conflict" > file | |
718 | ) && | |
719 | git checkout HEAD^ && | |
720 | (cd submodule2 && | |
ad6a599c | 721 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
722 | ) && |
723 | git config submodule.submodule.update rebase && | |
724 | test_must_fail git submodule update && | |
725 | (cd submodule2 && | |
ad6a599c | 726 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
727 | ) && |
728 | test_cmp expect actual | |
729 | ) | |
730 | ' | |
501770e1 FG |
731 | |
732 | test_expect_success 'add different submodules to the same path' ' | |
733 | (cd super && | |
734 | git submodule add ../submodule s1 && | |
735 | test_must_fail git submodule add ../merging s1 | |
736 | ) | |
737 | ' | |
738 | ||
739 | test_expect_success 'submodule add places git-dir in superprojects git-dir' ' | |
740 | (cd super && | |
741 | mkdir deeper && | |
742 | git submodule add ../submodule deeper/submodule && | |
743 | (cd deeper/submodule && | |
744 | git log > ../../expected | |
745 | ) && | |
746 | (cd .git/modules/deeper/submodule && | |
747 | git log > ../../../../actual | |
748 | ) && | |
749 | test_cmp actual expected | |
750 | ) | |
751 | ' | |
752 | ||
753 | test_expect_success 'submodule update places git-dir in superprojects git-dir' ' | |
754 | (cd super && | |
755 | git commit -m "added submodule" | |
756 | ) && | |
757 | git clone super super2 && | |
758 | (cd super2 && | |
759 | git submodule init deeper/submodule && | |
760 | git submodule update && | |
761 | (cd deeper/submodule && | |
762 | git log > ../../expected | |
763 | ) && | |
764 | (cd .git/modules/deeper/submodule && | |
765 | git log > ../../../../actual | |
766 | ) && | |
767 | test_cmp actual expected | |
768 | ) | |
769 | ' | |
770 | ||
771 | test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' | |
772 | (cd super2 && | |
773 | (cd deeper/submodule && | |
774 | git submodule add ../submodule subsubmodule && | |
775 | (cd subsubmodule && | |
776 | git log > ../../../expected | |
777 | ) && | |
778 | git commit -m "added subsubmodule" && | |
ae74f7d2 | 779 | git push origin : |
501770e1 FG |
780 | ) && |
781 | (cd .git/modules/deeper/submodule/modules/subsubmodule && | |
782 | git log > ../../../../../actual | |
783 | ) && | |
784 | git add deeper/submodule && | |
785 | git commit -m "update submodule" && | |
ae74f7d2 | 786 | git push origin : && |
501770e1 FG |
787 | test_cmp actual expected |
788 | ) | |
789 | ' | |
790 | ||
791 | test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' | |
792 | mkdir super_update_r && | |
793 | (cd super_update_r && | |
794 | git init --bare | |
795 | ) && | |
796 | mkdir subsuper_update_r && | |
797 | (cd subsuper_update_r && | |
798 | git init --bare | |
799 | ) && | |
800 | mkdir subsubsuper_update_r && | |
801 | (cd subsubsuper_update_r && | |
802 | git init --bare | |
803 | ) && | |
804 | git clone subsubsuper_update_r subsubsuper_update_r2 && | |
805 | (cd subsubsuper_update_r2 && | |
806 | test_commit "update_subsubsuper" file && | |
807 | git push origin master | |
808 | ) && | |
809 | git clone subsuper_update_r subsuper_update_r2 && | |
810 | (cd subsuper_update_r2 && | |
811 | test_commit "update_subsuper" file && | |
812 | git submodule add ../subsubsuper_update_r subsubmodule && | |
813 | git commit -am "subsubmodule" && | |
814 | git push origin master | |
815 | ) && | |
816 | git clone super_update_r super_update_r2 && | |
817 | (cd super_update_r2 && | |
818 | test_commit "update_super" file && | |
819 | git submodule add ../subsuper_update_r submodule && | |
820 | git commit -am "submodule" && | |
821 | git push origin master | |
822 | ) && | |
823 | rm -rf super_update_r2 && | |
824 | git clone super_update_r super_update_r2 && | |
825 | (cd super_update_r2 && | |
75bf5e60 | 826 | git submodule update --init --recursive >actual && |
d851ffb9 | 827 | test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual && |
501770e1 FG |
828 | (cd submodule/subsubmodule && |
829 | git log > ../../expected | |
830 | ) && | |
831 | (cd .git/modules/submodule/modules/subsubmodule | |
832 | git log > ../../../../../actual | |
833 | ) | |
834 | test_cmp actual expected | |
835 | ) | |
836 | ' | |
837 | ||
1017c1ab JL |
838 | test_expect_success 'submodule add properly re-creates deeper level submodules' ' |
839 | (cd super && | |
840 | git reset --hard master && | |
841 | rm -rf deeper/ && | |
4b7c286e | 842 | git submodule add --force ../submodule deeper/submodule |
1017c1ab JL |
843 | ) |
844 | ' | |
845 | ||
69c30517 JL |
846 | test_expect_success 'submodule update properly revives a moved submodule' ' |
847 | (cd super && | |
b397ea48 | 848 | H=$(git rev-parse --short HEAD) && |
69c30517 | 849 | git commit -am "pre move" && |
b397ea48 NTND |
850 | H2=$(git rev-parse --short HEAD) && |
851 | git status | sed "s/$H/XXX/" >expect && | |
69c30517 JL |
852 | H=$(cd submodule2; git rev-parse HEAD) && |
853 | git rm --cached submodule2 && | |
854 | rm -rf submodule2 && | |
855 | mkdir -p "moved/sub module" && | |
856 | git update-index --add --cacheinfo 160000 $H "moved/sub module" && | |
857 | git config -f .gitmodules submodule.submodule2.path "moved/sub module" | |
858 | git commit -am "post move" && | |
859 | git submodule update && | |
b397ea48 | 860 | git status | sed "s/$H2/XXX/" >actual && |
69c30517 JL |
861 | test_cmp expect actual |
862 | ) | |
863 | ' | |
864 | ||
6eafa6d0 JL |
865 | test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' |
866 | mkdir -p linked/dir && | |
867 | ln -s linked/dir linkto && | |
275cd184 FG |
868 | (cd linkto && |
869 | git clone "$TRASH_DIRECTORY"/super_update_r2 super && | |
870 | (cd super && | |
871 | git submodule update --init --recursive | |
872 | ) | |
6eafa6d0 JL |
873 | ) |
874 | ' | |
875 | ||
275cd184 | 876 | test_expect_success 'submodule update clone shallow submodule' ' |
d4470c5a SB |
877 | test_when_finished "rm -rf super3" && |
878 | first=$(git -C cloned submodule status submodule |cut -c2-41) && | |
879 | second=$(git -C submodule rev-parse HEAD) && | |
967d7f89 | 880 | commit_count=$(git -C submodule rev-list --count $first^..$second) && |
275cd184 | 881 | git clone cloned super3 && |
99094a7a | 882 | pwd=$(pwd) && |
d4470c5a SB |
883 | ( |
884 | cd super3 && | |
885 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && | |
886 | mv -f .gitmodules.tmp .gitmodules && | |
887 | git submodule update --init --depth=$commit_count && | |
888 | test 1 = $(git -C submodule log --oneline | wc -l) | |
889 | ) | |
36141282 JL |
890 | ' |
891 | ||
6cbf454a SB |
892 | test_expect_success 'submodule update clone shallow submodule outside of depth' ' |
893 | test_when_finished "rm -rf super3" && | |
894 | git clone cloned super3 && | |
895 | pwd=$(pwd) && | |
896 | ( | |
897 | cd super3 && | |
898 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && | |
899 | mv -f .gitmodules.tmp .gitmodules && | |
900 | test_must_fail git submodule update --init --depth=1 2>actual && | |
901 | test_i18ngrep "Direct fetching of that commit failed." actual && | |
902 | git -C ../submodule config uploadpack.allowReachableSHA1InWant true && | |
903 | git submodule update --init --depth=1 >actual && | |
904 | test 1 = $(git -C submodule log --oneline | wc -l) | |
905 | ) | |
906 | ' | |
907 | ||
36141282 JL |
908 | test_expect_success 'submodule update --recursive drops module name before recursing' ' |
909 | (cd super2 && | |
910 | (cd deeper/submodule/subsubmodule && | |
911 | git checkout HEAD^ | |
912 | ) && | |
913 | git submodule update --recursive deeper/submodule >actual && | |
914 | test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual | |
275cd184 FG |
915 | ) |
916 | ' | |
2335b870 SB |
917 | |
918 | test_expect_success 'submodule update can be run in parallel' ' | |
919 | (cd super2 && | |
920 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 && | |
921 | grep "7 tasks" trace.out && | |
922 | git config submodule.fetchJobs 8 && | |
923 | GIT_TRACE=$(pwd)/trace.out git submodule update && | |
924 | grep "8 tasks" trace.out && | |
925 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 && | |
926 | grep "9 tasks" trace.out | |
927 | ) | |
928 | ' | |
72290d6a SB |
929 | |
930 | test_expect_success 'git clone passes the parallel jobs config on to submodules' ' | |
931 | test_when_finished "rm -rf super4" && | |
932 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 && | |
933 | grep "7 tasks" trace.out && | |
934 | rm -rf super4 && | |
935 | git config --global submodule.fetchJobs 8 && | |
936 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 && | |
937 | grep "8 tasks" trace.out && | |
938 | rm -rf super4 && | |
939 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 && | |
940 | grep "9 tasks" trace.out && | |
941 | rm -rf super4 | |
942 | ' | |
943 | ||
ca2cedba | 944 | test_done |