]>
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 | ) && | |
aca8568e ÆAB |
209 | test_must_fail git submodule update submodule 2>../actual.raw |
210 | ) && | |
211 | sed "s/^> //" >expect <<-\EOF && | |
212 | > error: Your local changes to the following files would be overwritten by checkout: | |
213 | > file | |
214 | > Please commit your changes or stash them before you switch branches. | |
215 | > Aborting | |
216 | > fatal: Unable to checkout OID in submodule path '\''submodule'\'' | |
217 | EOF | |
218 | sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual && | |
219 | test_cmp expect actual | |
220 | ||
9db31bdf NMC |
221 | ' |
222 | test_expect_success 'submodule update should throw away changes with --force ' ' | |
223 | (cd super && | |
224 | (cd submodule && | |
225 | compare_head | |
226 | ) && | |
227 | git submodule update --force submodule && | |
228 | cd submodule && | |
229 | ! compare_head | |
230 | ) | |
231 | ' | |
232 | ||
01d47215 SZ |
233 | test_expect_success 'submodule update --force forcibly checks out submodules' ' |
234 | (cd super && | |
235 | (cd submodule && | |
236 | rm -f file | |
237 | ) && | |
238 | git submodule update --force submodule && | |
239 | (cd submodule && | |
240 | test "$(git status -s file)" = "" | |
241 | ) | |
242 | ) | |
243 | ' | |
244 | ||
06b1abb5 TK |
245 | test_expect_success 'submodule update --remote should fetch upstream changes' ' |
246 | (cd submodule && | |
247 | echo line4 >> file && | |
248 | git add file && | |
249 | test_tick && | |
250 | git commit -m "upstream line4" | |
251 | ) && | |
252 | (cd super && | |
253 | git submodule update --remote --force submodule && | |
254 | cd submodule && | |
255 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)" | |
256 | ) | |
257 | ' | |
258 | ||
4d7bc52b SB |
259 | test_expect_success 'submodule update --remote should fetch upstream changes with .' ' |
260 | ( | |
261 | cd super && | |
262 | git config -f .gitmodules submodule."submodule".branch "." && | |
263 | git add .gitmodules && | |
264 | git commit -m "submodules: update from the respective superproject branch" | |
265 | ) && | |
266 | ( | |
267 | cd submodule && | |
268 | echo line4a >> file && | |
269 | git add file && | |
270 | test_tick && | |
271 | git commit -m "upstream line4a" && | |
272 | git checkout -b test-branch && | |
273 | test_commit on-test-branch | |
274 | ) && | |
275 | ( | |
276 | cd super && | |
277 | git submodule update --remote --force submodule && | |
8de19d6b | 278 | git -C submodule log -1 --oneline >actual && |
01dc8133 | 279 | git -C ../submodule log -1 --oneline main >expect && |
4d7bc52b SB |
280 | test_cmp expect actual && |
281 | git checkout -b test-branch && | |
282 | git submodule update --remote --force submodule && | |
8de19d6b SG |
283 | git -C submodule log -1 --oneline >actual && |
284 | git -C ../submodule log -1 --oneline test-branch >expect && | |
4d7bc52b | 285 | test_cmp expect actual && |
01dc8133 | 286 | git checkout main && |
4d7bc52b SB |
287 | git branch -d test-branch && |
288 | git reset --hard HEAD^ | |
289 | ) | |
290 | ' | |
291 | ||
06b1abb5 TK |
292 | test_expect_success 'local config should override .gitmodules branch' ' |
293 | (cd submodule && | |
4d7bc52b | 294 | git checkout test-branch && |
06b1abb5 TK |
295 | echo line5 >> file && |
296 | git add file && | |
297 | test_tick && | |
298 | git commit -m "upstream line5" && | |
01dc8133 | 299 | git checkout main |
06b1abb5 TK |
300 | ) && |
301 | (cd super && | |
302 | git config submodule.submodule.branch test-branch && | |
303 | git submodule update --remote --force submodule && | |
304 | cd submodule && | |
305 | test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)" | |
306 | ) | |
307 | ' | |
308 | ||
01dc8133 | 309 | test_expect_success 'submodule update --rebase staying on main' ' |
ca2cedba | 310 | (cd super/submodule && |
01dc8133 | 311 | git checkout main |
ca2cedba PH |
312 | ) && |
313 | (cd super && | |
314 | (cd submodule && | |
315 | compare_head | |
316 | ) && | |
317 | git submodule update --rebase submodule && | |
318 | cd submodule && | |
319 | compare_head | |
320 | ) | |
321 | ' | |
322 | ||
01dc8133 | 323 | test_expect_success 'submodule update --merge staying on main' ' |
42b49178 JH |
324 | (cd super/submodule && |
325 | git reset --hard HEAD~1 | |
326 | ) && | |
327 | (cd super && | |
328 | (cd submodule && | |
329 | compare_head | |
330 | ) && | |
331 | git submodule update --merge submodule && | |
332 | cd submodule && | |
333 | compare_head | |
334 | ) | |
335 | ' | |
336 | ||
32948425 | 337 | test_expect_success 'submodule update - rebase in .git/config' ' |
ca2cedba | 338 | (cd super && |
32948425 | 339 | git config submodule.submodule.update rebase |
ca2cedba PH |
340 | ) && |
341 | (cd super/submodule && | |
342 | git reset --hard HEAD~1 | |
343 | ) && | |
344 | (cd super && | |
345 | (cd submodule && | |
346 | compare_head | |
347 | ) && | |
348 | git submodule update submodule && | |
349 | cd submodule && | |
350 | compare_head | |
351 | ) | |
352 | ' | |
353 | ||
32948425 | 354 | test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' |
ca2cedba | 355 | (cd super && |
32948425 | 356 | git config submodule.submodule.update checkout |
ca2cedba PH |
357 | ) && |
358 | (cd super/submodule && | |
359 | git reset --hard HEAD~1 | |
360 | ) && | |
361 | (cd super && | |
362 | (cd submodule && | |
363 | compare_head | |
364 | ) && | |
365 | git submodule update --rebase submodule && | |
366 | cd submodule && | |
367 | compare_head | |
368 | ) | |
369 | ' | |
370 | ||
42b49178 JH |
371 | test_expect_success 'submodule update - merge in .git/config' ' |
372 | (cd super && | |
373 | git config submodule.submodule.update merge | |
374 | ) && | |
375 | (cd super/submodule && | |
376 | git reset --hard HEAD~1 | |
377 | ) && | |
378 | (cd super && | |
379 | (cd submodule && | |
380 | compare_head | |
381 | ) && | |
382 | git submodule update submodule && | |
383 | cd submodule && | |
384 | compare_head | |
385 | ) | |
386 | ' | |
387 | ||
388 | test_expect_success 'submodule update - checkout in .git/config but --merge given' ' | |
389 | (cd super && | |
390 | git config submodule.submodule.update checkout | |
391 | ) && | |
392 | (cd super/submodule && | |
393 | git reset --hard HEAD~1 | |
394 | ) && | |
395 | (cd super && | |
396 | (cd submodule && | |
397 | compare_head | |
398 | ) && | |
399 | git submodule update --merge submodule && | |
400 | cd submodule && | |
401 | compare_head | |
402 | ) | |
403 | ' | |
404 | ||
32948425 | 405 | test_expect_success 'submodule update - checkout in .git/config' ' |
ca2cedba | 406 | (cd super && |
32948425 | 407 | git config submodule.submodule.update checkout |
ca2cedba PH |
408 | ) && |
409 | (cd super/submodule && | |
410 | git reset --hard HEAD^ | |
411 | ) && | |
412 | (cd super && | |
413 | (cd submodule && | |
414 | compare_head | |
415 | ) && | |
416 | git submodule update submodule && | |
417 | cd submodule && | |
418 | ! compare_head | |
419 | ) | |
420 | ' | |
421 | ||
6cb5728c CP |
422 | test_expect_success 'submodule update - command in .git/config' ' |
423 | (cd super && | |
424 | git config submodule.submodule.update "!git checkout" | |
425 | ) && | |
426 | (cd super/submodule && | |
427 | git reset --hard HEAD^ | |
428 | ) && | |
429 | (cd super && | |
430 | (cd submodule && | |
431 | compare_head | |
432 | ) && | |
433 | git submodule update submodule && | |
434 | cd submodule && | |
435 | ! compare_head | |
436 | ) | |
437 | ' | |
438 | ||
e904deb8 | 439 | test_expect_success 'submodule update - command in .gitmodules is rejected' ' |
83a17fa8 SB |
440 | test_when_finished "git -C super reset --hard HEAD^" && |
441 | git -C super config -f .gitmodules submodule.submodule.update "!false" && | |
442 | git -C super commit -a -m "add command to .gitmodules file" && | |
443 | git -C super/submodule reset --hard $submodulesha1^ && | |
e904deb8 | 444 | test_must_fail git -C super submodule update submodule |
83a17fa8 SB |
445 | ' |
446 | ||
bb92255e JN |
447 | test_expect_success 'fsck detects command in .gitmodules' ' |
448 | git init command-in-gitmodules && | |
449 | ( | |
450 | cd command-in-gitmodules && | |
451 | git submodule add ../submodule submodule && | |
452 | test_commit adding-submodule && | |
453 | ||
454 | git config -f .gitmodules submodule.submodule.update "!false" && | |
455 | git add .gitmodules && | |
456 | test_commit configuring-update && | |
457 | test_must_fail git fsck | |
458 | ) | |
83a17fa8 SB |
459 | ' |
460 | ||
b08238ac | 461 | cat << EOF >expect |
0008d122 | 462 | fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule' |
b08238ac SB |
463 | EOF |
464 | ||
6cb5728c CP |
465 | test_expect_success 'submodule update - command in .git/config catches failure' ' |
466 | (cd super && | |
467 | git config submodule.submodule.update "!false" | |
468 | ) && | |
469 | (cd super/submodule && | |
b08238ac | 470 | git reset --hard $submodulesha1^ |
6cb5728c CP |
471 | ) && |
472 | (cd super && | |
b08238ac SB |
473 | test_must_fail git submodule update submodule 2>../actual |
474 | ) && | |
1108cea7 | 475 | test_cmp actual expect |
b08238ac SB |
476 | ' |
477 | ||
478 | cat << EOF >expect | |
0008d122 | 479 | fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule' |
b08238ac SB |
480 | EOF |
481 | ||
482 | test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' ' | |
483 | (cd super && | |
484 | git config submodule.submodule.update "!false" | |
485 | ) && | |
486 | (cd super/submodule && | |
487 | git reset --hard $submodulesha1^ | |
488 | ) && | |
489 | (cd super && | |
490 | mkdir tmp && cd tmp && | |
491 | test_must_fail git submodule update ../submodule 2>../../actual | |
c1e06d11 | 492 | ) && |
1108cea7 | 493 | test_cmp actual expect |
c1e06d11 SB |
494 | ' |
495 | ||
e7b37caf | 496 | test_expect_success 'submodule update - command run for initial population of submodule' ' |
a4dded01 | 497 | cat >expect <<-EOF && |
0008d122 | 498 | fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\'' |
a4dded01 | 499 | EOF |
e7b37caf | 500 | rm -rf super/submodule && |
a4dded01 | 501 | test_must_fail git -C super submodule update 2>actual && |
1108cea7 | 502 | test_cmp expect actual && |
e7b37caf SB |
503 | git -C super submodule update --checkout |
504 | ' | |
505 | ||
c1e06d11 | 506 | cat << EOF >expect |
0008d122 AR |
507 | fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' |
508 | fatal: Failed to recurse into submodule path '../super' | |
c1e06d11 SB |
509 | EOF |
510 | ||
511 | test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' ' | |
512 | (cd recursivesuper && | |
513 | git submodule update --remote super && | |
514 | git add super && | |
515 | git commit -m "update to latest to have more than one commit in submodules" | |
516 | ) && | |
517 | git -C recursivesuper/super config submodule.submodule.update "!false" && | |
518 | git -C recursivesuper/super/submodule reset --hard $submodulesha1^ && | |
519 | (cd recursivesuper && | |
520 | mkdir -p tmp && cd tmp && | |
521 | test_must_fail git submodule update --recursive ../super 2>../../actual | |
b08238ac | 522 | ) && |
1108cea7 | 523 | test_cmp actual expect |
6cb5728c CP |
524 | ' |
525 | ||
ac1fbbda | 526 | test_expect_success 'submodule init does not copy command into .git/config' ' |
e904deb8 JN |
527 | test_when_finished "git -C super update-index --force-remove submodule1" && |
528 | test_when_finished git config -f super/.gitmodules \ | |
529 | --remove-section submodule.submodule1 && | |
ac1fbbda | 530 | (cd super && |
65799fbc EN |
531 | git ls-files -s submodule >out && |
532 | H=$(cut -d" " -f2 out) && | |
ac1fbbda JH |
533 | mkdir submodule1 && |
534 | git update-index --add --cacheinfo 160000 $H submodule1 && | |
535 | git config -f .gitmodules submodule.submodule1.path submodule1 && | |
536 | git config -f .gitmodules submodule.submodule1.url ../submodule && | |
537 | git config -f .gitmodules submodule.submodule1.update !false && | |
e904deb8 JN |
538 | test_must_fail git submodule init submodule1 && |
539 | test_expect_code 1 git config submodule.submodule1.update >actual && | |
540 | test_must_be_empty actual | |
ac1fbbda JH |
541 | ) |
542 | ' | |
543 | ||
ca2cedba PH |
544 | test_expect_success 'submodule init picks up rebase' ' |
545 | (cd super && | |
c9c8c56e | 546 | git config -f .gitmodules submodule.rebasing.update rebase && |
ca2cedba | 547 | git submodule init rebasing && |
c9c8c56e | 548 | test "rebase" = "$(git config submodule.rebasing.update)" |
ca2cedba PH |
549 | ) |
550 | ' | |
551 | ||
42b49178 JH |
552 | test_expect_success 'submodule init picks up merge' ' |
553 | (cd super && | |
c9c8c56e | 554 | git config -f .gitmodules submodule.merging.update merge && |
42b49178 | 555 | git submodule init merging && |
c9c8c56e | 556 | test "merge" = "$(git config submodule.merging.update)" |
42b49178 JH |
557 | ) |
558 | ' | |
559 | ||
b200021e | 560 | test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' |
e7b37caf | 561 | test_config -C super submodule.submodule.update checkout && |
b200021e SO |
562 | (cd super && |
563 | rm -rf submodule && | |
564 | git submodule update submodule && | |
565 | git status -s submodule >expect && | |
566 | rm -rf submodule && | |
567 | git submodule update --merge submodule && | |
568 | git status -s submodule >actual && | |
569 | test_cmp expect actual | |
570 | ) | |
571 | ' | |
572 | ||
573 | test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' | |
e7b37caf | 574 | test_config -C super submodule.submodule.update checkout && |
b200021e SO |
575 | (cd super && |
576 | rm -rf submodule && | |
577 | git submodule update submodule && | |
578 | git status -s submodule >expect && | |
579 | rm -rf submodule && | |
580 | git submodule update --rebase submodule && | |
581 | git status -s submodule >actual && | |
582 | test_cmp expect actual | |
583 | ) | |
584 | ' | |
585 | ||
586 | test_expect_success 'submodule update ignores update=merge config for new submodules' ' | |
587 | (cd super && | |
588 | rm -rf submodule && | |
589 | git submodule update submodule && | |
590 | git status -s submodule >expect && | |
591 | rm -rf submodule && | |
592 | git config submodule.submodule.update merge && | |
593 | git submodule update submodule && | |
594 | git status -s submodule >actual && | |
595 | git config --unset submodule.submodule.update && | |
596 | test_cmp expect actual | |
597 | ) | |
598 | ' | |
599 | ||
600 | test_expect_success 'submodule update ignores update=rebase config for new submodules' ' | |
601 | (cd super && | |
602 | rm -rf submodule && | |
603 | git submodule update submodule && | |
604 | git status -s submodule >expect && | |
605 | rm -rf submodule && | |
606 | git config submodule.submodule.update rebase && | |
607 | git submodule update submodule && | |
608 | git status -s submodule >actual && | |
609 | git config --unset submodule.submodule.update && | |
610 | test_cmp expect actual | |
611 | ) | |
612 | ' | |
613 | ||
322bb6e1 HV |
614 | test_expect_success 'submodule init picks up update=none' ' |
615 | (cd super && | |
616 | git config -f .gitmodules submodule.none.update none && | |
617 | git submodule init none && | |
618 | test "none" = "$(git config submodule.none.update)" | |
619 | ) | |
620 | ' | |
621 | ||
622 | test_expect_success 'submodule update - update=none in .git/config' ' | |
623 | (cd super && | |
624 | git config submodule.submodule.update none && | |
625 | (cd submodule && | |
01dc8133 | 626 | git checkout main && |
322bb6e1 HV |
627 | compare_head |
628 | ) && | |
65799fbc EN |
629 | git diff --name-only >out && |
630 | grep ^submodule$ out && | |
322bb6e1 | 631 | git submodule update && |
65799fbc EN |
632 | git diff --name-only >out && |
633 | grep ^submodule$ out && | |
322bb6e1 HV |
634 | (cd submodule && |
635 | compare_head | |
636 | ) && | |
637 | git config --unset submodule.submodule.update && | |
638 | git submodule update submodule | |
639 | ) | |
640 | ' | |
641 | ||
642 | test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' | |
643 | (cd super && | |
644 | git config submodule.submodule.update none && | |
645 | (cd submodule && | |
01dc8133 | 646 | git checkout main && |
322bb6e1 HV |
647 | compare_head |
648 | ) && | |
65799fbc EN |
649 | git diff --name-only >out && |
650 | grep ^submodule$ out && | |
322bb6e1 | 651 | git submodule update --checkout && |
602813cf EN |
652 | git diff --name-only >out && |
653 | ! grep ^submodule$ out && | |
322bb6e1 | 654 | (cd submodule && |
9fd1080a | 655 | ! compare_head |
322bb6e1 HV |
656 | ) && |
657 | git config --unset submodule.submodule.update | |
658 | ) | |
659 | ' | |
660 | ||
661 | test_expect_success 'submodule update --init skips submodule with update=none' ' | |
662 | (cd super && | |
663 | git add .gitmodules && | |
664 | git commit -m ".gitmodules" | |
665 | ) && | |
666 | git clone super cloned && | |
667 | (cd cloned && | |
668 | git submodule update --init && | |
7e9055bb EN |
669 | test_path_exists submodule/.git && |
670 | test_path_is_missing none/.git | |
322bb6e1 HV |
671 | ) |
672 | ' | |
673 | ||
4f1ccef8 OS |
674 | test_expect_success 'submodule update with pathspec warns against uninitialized ones' ' |
675 | test_when_finished "rm -fr selective" && | |
676 | git clone super selective && | |
677 | ( | |
678 | cd selective && | |
679 | git submodule init submodule && | |
680 | ||
681 | git submodule update submodule 2>err && | |
682 | ! grep "Submodule path .* not initialized" err && | |
683 | ||
684 | git submodule update rebasing 2>err && | |
685 | grep "Submodule path .rebasing. not initialized" err && | |
686 | ||
687 | test_path_exists submodule/.git && | |
688 | test_path_is_missing rebasing/.git | |
689 | ) | |
690 | ||
691 | ' | |
692 | ||
693 | test_expect_success 'submodule update without pathspec updates only initialized ones' ' | |
694 | test_when_finished "rm -fr selective" && | |
695 | git clone super selective && | |
696 | ( | |
697 | cd selective && | |
698 | git submodule init submodule && | |
699 | git submodule update 2>err && | |
700 | test_path_exists submodule/.git && | |
701 | test_path_is_missing rebasing/.git && | |
702 | ! grep "Submodule path .* not initialized" err | |
703 | ) | |
704 | ||
705 | ' | |
706 | ||
15ffb7cd FG |
707 | test_expect_success 'submodule update continues after checkout error' ' |
708 | (cd super && | |
709 | git reset --hard HEAD && | |
710 | git submodule add ../submodule submodule2 && | |
711 | git submodule init && | |
712 | git commit -am "new_submodule" && | |
713 | (cd submodule2 && | |
ad6a599c | 714 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
715 | ) && |
716 | (cd submodule && | |
717 | test_commit "update_submodule" file | |
718 | ) && | |
719 | (cd submodule2 && | |
720 | test_commit "update_submodule2" file | |
721 | ) && | |
722 | git add submodule && | |
723 | git add submodule2 && | |
724 | git commit -m "two_new_submodule_commits" && | |
725 | (cd submodule && | |
726 | echo "" > file | |
727 | ) && | |
728 | git checkout HEAD^ && | |
729 | test_must_fail git submodule update && | |
730 | (cd submodule2 && | |
ad6a599c | 731 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
732 | ) && |
733 | test_cmp expect actual | |
734 | ) | |
735 | ' | |
736 | test_expect_success 'submodule update continues after recursive checkout error' ' | |
737 | (cd super && | |
738 | git reset --hard HEAD && | |
01dc8133 | 739 | git checkout main && |
15ffb7cd FG |
740 | git submodule update && |
741 | (cd submodule && | |
742 | git submodule add ../submodule subsubmodule && | |
743 | git submodule init && | |
744 | git commit -m "new_subsubmodule" | |
745 | ) && | |
746 | git add submodule && | |
747 | git commit -m "update_submodule" && | |
748 | (cd submodule && | |
749 | (cd subsubmodule && | |
750 | test_commit "update_subsubmodule" file | |
751 | ) && | |
752 | git add subsubmodule && | |
753 | test_commit "update_submodule_again" file && | |
754 | (cd subsubmodule && | |
755 | test_commit "update_subsubmodule_again" file | |
756 | ) && | |
757 | test_commit "update_submodule_again_again" file | |
758 | ) && | |
759 | (cd submodule2 && | |
ad6a599c | 760 | git rev-parse --verify HEAD >../expect && |
15ffb7cd FG |
761 | test_commit "update_submodule2_again" file |
762 | ) && | |
763 | git add submodule && | |
764 | git add submodule2 && | |
765 | git commit -m "new_commits" && | |
766 | git checkout HEAD^ && | |
767 | (cd submodule && | |
768 | git checkout HEAD^ && | |
769 | (cd subsubmodule && | |
770 | echo "" > file | |
771 | ) | |
772 | ) && | |
0b917a9f | 773 | test_expect_code 1 git submodule update --recursive && |
15ffb7cd | 774 | (cd submodule2 && |
ad6a599c | 775 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
776 | ) && |
777 | test_cmp expect actual | |
778 | ) | |
779 | ' | |
780 | ||
781 | test_expect_success 'submodule update exit immediately in case of merge conflict' ' | |
782 | (cd super && | |
01dc8133 | 783 | git checkout main && |
15ffb7cd FG |
784 | git reset --hard HEAD && |
785 | (cd submodule && | |
786 | (cd subsubmodule && | |
787 | git reset --hard HEAD | |
788 | ) | |
789 | ) && | |
790 | git submodule update --recursive && | |
791 | (cd submodule && | |
792 | test_commit "update_submodule_2" file | |
793 | ) && | |
794 | (cd submodule2 && | |
795 | test_commit "update_submodule2_2" file | |
796 | ) && | |
797 | git add submodule && | |
798 | git add submodule2 && | |
799 | git commit -m "two_new_submodule_commits" && | |
800 | (cd submodule && | |
01dc8133 | 801 | git checkout main && |
15ffb7cd FG |
802 | test_commit "conflict" file && |
803 | echo "conflict" > file | |
804 | ) && | |
805 | git checkout HEAD^ && | |
806 | (cd submodule2 && | |
ad6a599c | 807 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
808 | ) && |
809 | git config submodule.submodule.update merge && | |
810 | test_must_fail git submodule update && | |
811 | (cd submodule2 && | |
ad6a599c | 812 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
813 | ) && |
814 | test_cmp expect actual | |
815 | ) | |
816 | ' | |
501770e1 | 817 | |
15ffb7cd FG |
818 | test_expect_success 'submodule update exit immediately after recursive rebase error' ' |
819 | (cd super && | |
01dc8133 | 820 | git checkout main && |
15ffb7cd FG |
821 | git reset --hard HEAD && |
822 | (cd submodule && | |
823 | git reset --hard HEAD && | |
824 | git submodule update --recursive | |
825 | ) && | |
826 | (cd submodule && | |
827 | test_commit "update_submodule_3" file | |
828 | ) && | |
829 | (cd submodule2 && | |
830 | test_commit "update_submodule2_3" file | |
831 | ) && | |
832 | git add submodule && | |
833 | git add submodule2 && | |
834 | git commit -m "two_new_submodule_commits" && | |
835 | (cd submodule && | |
01dc8133 | 836 | git checkout main && |
15ffb7cd FG |
837 | test_commit "conflict2" file && |
838 | echo "conflict" > file | |
839 | ) && | |
840 | git checkout HEAD^ && | |
841 | (cd submodule2 && | |
ad6a599c | 842 | git rev-parse --verify HEAD >../expect |
15ffb7cd FG |
843 | ) && |
844 | git config submodule.submodule.update rebase && | |
845 | test_must_fail git submodule update && | |
846 | (cd submodule2 && | |
ad6a599c | 847 | git rev-parse --verify HEAD >../actual |
15ffb7cd FG |
848 | ) && |
849 | test_cmp expect actual | |
850 | ) | |
851 | ' | |
501770e1 FG |
852 | |
853 | test_expect_success 'add different submodules to the same path' ' | |
854 | (cd super && | |
855 | git submodule add ../submodule s1 && | |
856 | test_must_fail git submodule add ../merging s1 | |
857 | ) | |
858 | ' | |
859 | ||
860 | test_expect_success 'submodule add places git-dir in superprojects git-dir' ' | |
861 | (cd super && | |
862 | mkdir deeper && | |
863 | git submodule add ../submodule deeper/submodule && | |
864 | (cd deeper/submodule && | |
865 | git log > ../../expected | |
866 | ) && | |
867 | (cd .git/modules/deeper/submodule && | |
868 | git log > ../../../../actual | |
869 | ) && | |
dcbaa0b3 | 870 | test_cmp expected actual |
501770e1 FG |
871 | ) |
872 | ' | |
873 | ||
874 | test_expect_success 'submodule update places git-dir in superprojects git-dir' ' | |
875 | (cd super && | |
876 | git commit -m "added submodule" | |
877 | ) && | |
878 | git clone super super2 && | |
879 | (cd super2 && | |
880 | git submodule init deeper/submodule && | |
881 | git submodule update && | |
882 | (cd deeper/submodule && | |
883 | git log > ../../expected | |
884 | ) && | |
885 | (cd .git/modules/deeper/submodule && | |
886 | git log > ../../../../actual | |
887 | ) && | |
dcbaa0b3 | 888 | test_cmp expected actual |
501770e1 FG |
889 | ) |
890 | ' | |
891 | ||
892 | test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' | |
893 | (cd super2 && | |
894 | (cd deeper/submodule && | |
895 | git submodule add ../submodule subsubmodule && | |
896 | (cd subsubmodule && | |
897 | git log > ../../../expected | |
898 | ) && | |
899 | git commit -m "added subsubmodule" && | |
ae74f7d2 | 900 | git push origin : |
501770e1 FG |
901 | ) && |
902 | (cd .git/modules/deeper/submodule/modules/subsubmodule && | |
903 | git log > ../../../../../actual | |
904 | ) && | |
905 | git add deeper/submodule && | |
906 | git commit -m "update submodule" && | |
ae74f7d2 | 907 | git push origin : && |
dcbaa0b3 | 908 | test_cmp expected actual |
501770e1 FG |
909 | ) |
910 | ' | |
911 | ||
912 | test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' | |
913 | mkdir super_update_r && | |
914 | (cd super_update_r && | |
915 | git init --bare | |
916 | ) && | |
917 | mkdir subsuper_update_r && | |
918 | (cd subsuper_update_r && | |
919 | git init --bare | |
920 | ) && | |
921 | mkdir subsubsuper_update_r && | |
922 | (cd subsubsuper_update_r && | |
923 | git init --bare | |
924 | ) && | |
925 | git clone subsubsuper_update_r subsubsuper_update_r2 && | |
926 | (cd subsubsuper_update_r2 && | |
927 | test_commit "update_subsubsuper" file && | |
01dc8133 | 928 | git push origin main |
501770e1 FG |
929 | ) && |
930 | git clone subsuper_update_r subsuper_update_r2 && | |
931 | (cd subsuper_update_r2 && | |
932 | test_commit "update_subsuper" file && | |
933 | git submodule add ../subsubsuper_update_r subsubmodule && | |
934 | git commit -am "subsubmodule" && | |
01dc8133 | 935 | git push origin main |
501770e1 FG |
936 | ) && |
937 | git clone super_update_r super_update_r2 && | |
938 | (cd super_update_r2 && | |
939 | test_commit "update_super" file && | |
940 | git submodule add ../subsuper_update_r submodule && | |
941 | git commit -am "submodule" && | |
01dc8133 | 942 | git push origin main |
501770e1 FG |
943 | ) && |
944 | rm -rf super_update_r2 && | |
945 | git clone super_update_r super_update_r2 && | |
946 | (cd super_update_r2 && | |
75bf5e60 | 947 | git submodule update --init --recursive >actual && |
6789275d | 948 | test_grep "Submodule path .submodule/subsubmodule.: checked out" actual && |
501770e1 FG |
949 | (cd submodule/subsubmodule && |
950 | git log > ../../expected | |
951 | ) && | |
e974e06d | 952 | (cd .git/modules/submodule/modules/subsubmodule && |
501770e1 | 953 | git log > ../../../../../actual |
e974e06d | 954 | ) && |
dcbaa0b3 | 955 | test_cmp expected actual |
501770e1 FG |
956 | ) |
957 | ' | |
958 | ||
1017c1ab JL |
959 | test_expect_success 'submodule add properly re-creates deeper level submodules' ' |
960 | (cd super && | |
01dc8133 | 961 | git reset --hard main && |
1017c1ab | 962 | rm -rf deeper/ && |
4b7c286e | 963 | git submodule add --force ../submodule deeper/submodule |
1017c1ab JL |
964 | ) |
965 | ' | |
966 | ||
69c30517 JL |
967 | test_expect_success 'submodule update properly revives a moved submodule' ' |
968 | (cd super && | |
b397ea48 | 969 | H=$(git rev-parse --short HEAD) && |
69c30517 | 970 | git commit -am "pre move" && |
b397ea48 | 971 | H2=$(git rev-parse --short HEAD) && |
65799fbc EN |
972 | git status >out && |
973 | sed "s/$H/XXX/" out >expect && | |
e974e06d | 974 | H=$(cd submodule2 && git rev-parse HEAD) && |
69c30517 JL |
975 | git rm --cached submodule2 && |
976 | rm -rf submodule2 && | |
977 | mkdir -p "moved/sub module" && | |
978 | git update-index --add --cacheinfo 160000 $H "moved/sub module" && | |
8de19d6b | 979 | git config -f .gitmodules submodule.submodule2.path "moved/sub module" && |
69c30517 JL |
980 | git commit -am "post move" && |
981 | git submodule update && | |
65799fbc EN |
982 | git status > out && |
983 | sed "s/$H2/XXX/" out >actual && | |
69c30517 JL |
984 | test_cmp expect actual |
985 | ) | |
986 | ' | |
987 | ||
6eafa6d0 JL |
988 | test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' |
989 | mkdir -p linked/dir && | |
990 | ln -s linked/dir linkto && | |
275cd184 FG |
991 | (cd linkto && |
992 | git clone "$TRASH_DIRECTORY"/super_update_r2 super && | |
993 | (cd super && | |
994 | git submodule update --init --recursive | |
995 | ) | |
6eafa6d0 JL |
996 | ) |
997 | ' | |
998 | ||
275cd184 | 999 | test_expect_success 'submodule update clone shallow submodule' ' |
d4470c5a | 1000 | test_when_finished "rm -rf super3" && |
65799fbc | 1001 | first=$(git -C cloned rev-parse HEAD:submodule) && |
d4470c5a | 1002 | second=$(git -C submodule rev-parse HEAD) && |
967d7f89 | 1003 | commit_count=$(git -C submodule rev-list --count $first^..$second) && |
275cd184 | 1004 | git clone cloned super3 && |
99094a7a | 1005 | pwd=$(pwd) && |
d4470c5a SB |
1006 | ( |
1007 | cd super3 && | |
1008 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && | |
1009 | mv -f .gitmodules.tmp .gitmodules && | |
1010 | git submodule update --init --depth=$commit_count && | |
65799fbc EN |
1011 | git -C submodule log --oneline >out && |
1012 | test_line_count = 1 out | |
d4470c5a | 1013 | ) |
36141282 JL |
1014 | ' |
1015 | ||
6cbf454a SB |
1016 | test_expect_success 'submodule update clone shallow submodule outside of depth' ' |
1017 | test_when_finished "rm -rf super3" && | |
1018 | git clone cloned super3 && | |
1019 | pwd=$(pwd) && | |
1020 | ( | |
1021 | cd super3 && | |
1022 | sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && | |
1023 | mv -f .gitmodules.tmp .gitmodules && | |
ab0c5f50 JT |
1024 | # Some protocol versions (e.g. 2) support fetching |
1025 | # unadvertised objects, so restrict this test to v0. | |
8a1b0978 | 1026 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
ab0c5f50 | 1027 | git submodule update --init --depth=1 2>actual && |
6789275d | 1028 | test_grep "Direct fetching of that commit failed." actual && |
6cbf454a SB |
1029 | git -C ../submodule config uploadpack.allowReachableSHA1InWant true && |
1030 | git submodule update --init --depth=1 >actual && | |
65799fbc EN |
1031 | git -C submodule log --oneline >out && |
1032 | test_line_count = 1 out | |
6cbf454a SB |
1033 | ) |
1034 | ' | |
1035 | ||
36141282 JL |
1036 | test_expect_success 'submodule update --recursive drops module name before recursing' ' |
1037 | (cd super2 && | |
1038 | (cd deeper/submodule/subsubmodule && | |
1039 | git checkout HEAD^ | |
1040 | ) && | |
1041 | git submodule update --recursive deeper/submodule >actual && | |
6789275d | 1042 | test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual |
275cd184 FG |
1043 | ) |
1044 | ' | |
2335b870 SB |
1045 | |
1046 | test_expect_success 'submodule update can be run in parallel' ' | |
1047 | (cd super2 && | |
1048 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 && | |
1049 | grep "7 tasks" trace.out && | |
1050 | git config submodule.fetchJobs 8 && | |
1051 | GIT_TRACE=$(pwd)/trace.out git submodule update && | |
1052 | grep "8 tasks" trace.out && | |
1053 | GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 && | |
1054 | grep "9 tasks" trace.out | |
1055 | ) | |
1056 | ' | |
72290d6a SB |
1057 | |
1058 | test_expect_success 'git clone passes the parallel jobs config on to submodules' ' | |
1059 | test_when_finished "rm -rf super4" && | |
1060 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 && | |
1061 | grep "7 tasks" trace.out && | |
1062 | rm -rf super4 && | |
1063 | git config --global submodule.fetchJobs 8 && | |
1064 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 && | |
1065 | grep "8 tasks" trace.out && | |
1066 | rm -rf super4 && | |
1067 | GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 && | |
1068 | grep "9 tasks" trace.out && | |
1069 | rm -rf super4 | |
1070 | ' | |
1071 | ||
3ad0401e TD |
1072 | test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ' |
1073 | (cd super && | |
1074 | test_commit -C rebasing message && | |
1075 | git submodule update --rebase --quiet >out 2>err && | |
1076 | test_must_be_empty out && | |
1077 | test_must_be_empty err && | |
0d68ee72 | 1078 | git submodule update --rebase >out 2>err && |
3ad0401e TD |
1079 | test_file_not_empty out && |
1080 | test_must_be_empty err | |
1081 | ) | |
1082 | ' | |
1083 | ||
62af4bdd NC |
1084 | test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' ' |
1085 | test_when_finished "rm -rf super4 super5 super6" && | |
1086 | git clone . super4 && | |
1087 | (cd super4 && | |
1088 | git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 && | |
1089 | git commit -am "setup submodule3" | |
1090 | ) && | |
1091 | (cd submodule && | |
1092 | test_commit line6 file | |
1093 | ) && | |
1094 | git clone super4 super5 && | |
1095 | (cd super5 && | |
1096 | git submodule update --quiet --init --depth=1 submodule3 >out 2>err && | |
1097 | test_must_be_empty out && | |
1098 | test_must_be_empty err | |
1099 | ) && | |
1100 | git clone super4 super6 && | |
1101 | (cd super6 && | |
1102 | git submodule update --init --depth=1 submodule3 >out 2>err && | |
1103 | test_file_not_empty out && | |
1104 | test_file_not_empty err | |
1105 | ) | |
1106 | ' | |
1107 | ||
104744f9 GC |
1108 | test_expect_success 'submodule update --filter requires --init' ' |
1109 | test_expect_code 129 git -C super submodule update --filter blob:none | |
1110 | ' | |
1111 | ||
1112 | test_expect_success 'submodule update --filter sets partial clone settings' ' | |
1113 | test_when_finished "rm -rf super-filter" && | |
1114 | git clone cloned super-filter && | |
1115 | git -C super-filter submodule update --init --filter blob:none && | |
1116 | test_cmp_config -C super-filter/submodule true remote.origin.promisor && | |
1117 | test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter | |
1118 | ' | |
1119 | ||
8fc36c39 GC |
1120 | # NEEDSWORK: Clean up the tests so that we can reuse the test setup. |
1121 | # Don't reuse the existing repos because the earlier tests have | |
1122 | # intentionally disruptive configurations. | |
1123 | test_expect_success 'setup clean recursive superproject' ' | |
1124 | git init bottom && | |
1125 | test_commit -C bottom "bottom" && | |
1126 | git init middle && | |
1127 | git -C middle submodule add ../bottom bottom && | |
1128 | git -C middle commit -m "middle" && | |
1129 | git init top && | |
1130 | git -C top submodule add ../middle middle && | |
1131 | git -C top commit -m "top" && | |
1132 | git clone --recurse-submodules top top-clean | |
1133 | ' | |
1134 | ||
1135 | test_expect_success 'submodule update should skip unmerged submodules' ' | |
1136 | test_when_finished "rm -fr top-cloned" && | |
1137 | cp -r top-clean top-cloned && | |
1138 | ||
1139 | # Create an upstream commit in each repo, starting with bottom | |
1140 | test_commit -C bottom upstream_commit && | |
1141 | # Create middle commit | |
1142 | git -C middle/bottom fetch && | |
1143 | git -C middle/bottom checkout -f FETCH_HEAD && | |
1144 | git -C middle add bottom && | |
1145 | git -C middle commit -m "upstream_commit" && | |
1146 | # Create top commit | |
1147 | git -C top/middle fetch && | |
1148 | git -C top/middle checkout -f FETCH_HEAD && | |
1149 | git -C top add middle && | |
1150 | git -C top commit -m "upstream_commit" && | |
1151 | ||
1152 | # Create a downstream conflict | |
1153 | test_commit -C top-cloned/middle/bottom downstream_commit && | |
1154 | git -C top-cloned/middle add bottom && | |
1155 | git -C top-cloned/middle commit -m "downstream_commit" && | |
1156 | git -C top-cloned/middle fetch --recurse-submodules origin && | |
1157 | test_must_fail git -C top-cloned/middle merge origin/main && | |
1158 | ||
1159 | # Make the update of "middle" a no-op, otherwise we error out | |
1160 | # because of its unmerged state | |
1161 | test_config -C top-cloned submodule.middle.update !true && | |
1162 | git -C top-cloned submodule update --recursive 2>actual.err && | |
1163 | cat >expect.err <<-\EOF && | |
618b8445 | 1164 | Skipping unmerged submodule middle/bottom |
8fc36c39 GC |
1165 | EOF |
1166 | test_cmp expect.err actual.err | |
1167 | ' | |
1168 | ||
1169 | test_expect_success 'submodule update --recursive skip submodules with strategy=none' ' | |
1170 | test_when_finished "rm -fr top-cloned" && | |
1171 | cp -r top-clean top-cloned && | |
1172 | ||
1173 | test_commit -C top-cloned/middle/bottom downstream_commit && | |
1174 | git -C top-cloned/middle config submodule.bottom.update none && | |
1175 | git -C top-cloned submodule update --recursive 2>actual.err && | |
1176 | cat >expect.err <<-\EOF && | |
618b8445 | 1177 | Skipping submodule '\''middle/bottom'\'' |
8fc36c39 GC |
1178 | EOF |
1179 | test_cmp expect.err actual.err | |
1180 | ' | |
1181 | ||
5768478e JS |
1182 | add_submodule_commit_and_validate () { |
1183 | HASH=$(git rev-parse HEAD) && | |
1184 | git update-index --add --cacheinfo 160000,$HASH,sub && | |
1185 | git commit -m "create submodule" && | |
1186 | echo "160000 commit $HASH sub" >expect && | |
1187 | git ls-tree HEAD -- sub >actual && | |
1188 | test_cmp expect actual | |
1189 | } | |
1190 | ||
1191 | test_expect_success 'commit with staged submodule change' ' | |
1192 | add_submodule_commit_and_validate | |
1193 | ' | |
1194 | ||
1195 | test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' ' | |
1196 | test_config diff.ignoreSubmodules dirty && | |
1197 | add_submodule_commit_and_validate | |
1198 | ' | |
1199 | ||
1200 | test_expect_success 'commit with staged submodule change with ignoreSubmodules all' ' | |
1201 | test_config diff.ignoreSubmodules all && | |
1202 | add_submodule_commit_and_validate | |
1203 | ' | |
1204 | ||
97065761 JS |
1205 | test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \ |
1206 | 'submodule paths must not follow symlinks' ' | |
1207 | ||
1208 | # This is only needed because we want to run this in a self-contained | |
1209 | # test without having to spin up an HTTP server; However, it would not | |
1210 | # be needed in a real-world scenario where the submodule is simply | |
1211 | # hosted on a public site. | |
1212 | test_config_global protocol.file.allow always && | |
1213 | ||
1214 | # Make sure that Git tries to use symlinks on Windows | |
1215 | test_config_global core.symlinks true && | |
1216 | ||
1217 | tell_tale_path="$PWD/tell.tale" && | |
1218 | git init hook && | |
1219 | ( | |
1220 | cd hook && | |
1221 | mkdir -p y/hooks && | |
1222 | write_script y/hooks/post-checkout <<-EOF && | |
1223 | echo HOOK-RUN >&2 | |
1224 | echo hook-run >"$tell_tale_path" | |
1225 | EOF | |
1226 | git add y/hooks/post-checkout && | |
1227 | test_tick && | |
1228 | git commit -m post-checkout | |
1229 | ) && | |
1230 | ||
1231 | hook_repo_path="$(pwd)/hook" && | |
1232 | git init captain && | |
1233 | ( | |
1234 | cd captain && | |
1235 | git submodule add --name x/y "$hook_repo_path" A/modules/x && | |
1236 | test_tick && | |
1237 | git commit -m add-submodule && | |
1238 | ||
1239 | printf .git >dotgit.txt && | |
1240 | git hash-object -w --stdin <dotgit.txt >dot-git.hash && | |
1241 | printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" >index.info && | |
1242 | git update-index --index-info <index.info && | |
1243 | test_tick && | |
1244 | git commit -m add-symlink | |
1245 | ) && | |
1246 | ||
1247 | test_path_is_missing "$tell_tale_path" && | |
31572dc4 | 1248 | git clone --recursive captain hooked 2>err && |
8e97ec36 | 1249 | test_grep ! HOOK-RUN err && |
97065761 JS |
1250 | test_path_is_missing "$tell_tale_path" |
1251 | ' | |
1252 | ||
ca2cedba | 1253 | test_done |