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