]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # Copyright (c) 2007 Lars Hjemli | |
4 | # | |
5 | ||
6 | test_description='Basic porcelain support for submodules | |
7 | ||
8 | This test tries to verify basic sanity of the init, update and status | |
9 | subcommands of git submodule. | |
10 | ' | |
11 | ||
12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | |
13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
14 | ||
15 | . ./test-lib.sh | |
16 | ||
17 | test_expect_success 'submodule deinit works on empty repository' ' | |
18 | git submodule deinit --all | |
19 | ' | |
20 | ||
21 | test_expect_success 'setup - initial commit' ' | |
22 | >t && | |
23 | git add t && | |
24 | git commit -m "initial commit" && | |
25 | git branch initial | |
26 | ' | |
27 | ||
28 | test_expect_success 'submodule init aborts on missing .gitmodules file' ' | |
29 | test_when_finished "git update-index --remove sub" && | |
30 | git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && | |
31 | # missing the .gitmodules file here | |
32 | test_must_fail git submodule init 2>actual && | |
33 | test_i18ngrep "No url found for submodule path" actual | |
34 | ' | |
35 | ||
36 | test_expect_success 'submodule update aborts on missing .gitmodules file' ' | |
37 | test_when_finished "git update-index --remove sub" && | |
38 | git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && | |
39 | # missing the .gitmodules file here | |
40 | git submodule update sub 2>actual && | |
41 | test_i18ngrep "Submodule path .sub. not initialized" actual | |
42 | ' | |
43 | ||
44 | test_expect_success 'submodule update aborts on missing gitmodules url' ' | |
45 | test_when_finished "git update-index --remove sub" && | |
46 | git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && | |
47 | test_when_finished "rm -f .gitmodules" && | |
48 | git config -f .gitmodules submodule.s.path sub && | |
49 | test_must_fail git submodule init | |
50 | ' | |
51 | ||
52 | test_expect_success 'add aborts on repository with no commits' ' | |
53 | cat >expect <<-\EOF && | |
54 | '"'repo-no-commits'"' does not have a commit checked out | |
55 | EOF | |
56 | git init repo-no-commits && | |
57 | test_must_fail git submodule add ../a ./repo-no-commits 2>actual && | |
58 | test_cmp expect actual | |
59 | ' | |
60 | ||
61 | test_expect_success 'status should ignore inner git repo when not added' ' | |
62 | rm -fr inner && | |
63 | mkdir inner && | |
64 | ( | |
65 | cd inner && | |
66 | git init && | |
67 | >t && | |
68 | git add t && | |
69 | git commit -m "initial" | |
70 | ) && | |
71 | test_must_fail git submodule status inner 2>output.err && | |
72 | rm -fr inner && | |
73 | test_i18ngrep "^error: .*did not match any file(s) known to git" output.err | |
74 | ' | |
75 | ||
76 | test_expect_success 'setup - repository in init subdirectory' ' | |
77 | mkdir init && | |
78 | ( | |
79 | cd init && | |
80 | git init && | |
81 | echo a >a && | |
82 | git add a && | |
83 | git commit -m "submodule commit 1" && | |
84 | git tag -a -m "rev-1" rev-1 | |
85 | ) | |
86 | ' | |
87 | ||
88 | test_expect_success 'setup - commit with gitlink' ' | |
89 | echo a >a && | |
90 | echo z >z && | |
91 | git add a init z && | |
92 | git commit -m "super commit 1" | |
93 | ' | |
94 | ||
95 | test_expect_success 'setup - hide init subdirectory' ' | |
96 | mv init .subrepo | |
97 | ' | |
98 | ||
99 | test_expect_success 'setup - repository to add submodules to' ' | |
100 | git init addtest && | |
101 | git init addtest-ignore | |
102 | ' | |
103 | ||
104 | # The 'submodule add' tests need some repository to add as a submodule. | |
105 | # The trash directory is a good one as any. We need to canonicalize | |
106 | # the name, though, as some tests compare it to the absolute path git | |
107 | # generates, which will expand symbolic links. | |
108 | submodurl=$(pwd -P) | |
109 | ||
110 | listbranches() { | |
111 | git for-each-ref --format='%(refname)' 'refs/heads/*' | |
112 | } | |
113 | ||
114 | inspect() { | |
115 | dir=$1 && | |
116 | dotdot="${2:-..}" && | |
117 | ||
118 | ( | |
119 | cd "$dir" && | |
120 | listbranches >"$dotdot/heads" && | |
121 | { git symbolic-ref HEAD || :; } >"$dotdot/head" && | |
122 | git rev-parse HEAD >"$dotdot/head-sha1" && | |
123 | git update-index --refresh && | |
124 | git diff-files --exit-code && | |
125 | git clean -n -d -x >"$dotdot/untracked" | |
126 | ) | |
127 | } | |
128 | ||
129 | test_expect_success 'submodule add' ' | |
130 | echo "refs/heads/main" >expect && | |
131 | ||
132 | ( | |
133 | cd addtest && | |
134 | git submodule add -q "$submodurl" submod >actual && | |
135 | test_must_be_empty actual && | |
136 | echo "gitdir: ../.git/modules/submod" >expect && | |
137 | test_cmp expect submod/.git && | |
138 | ( | |
139 | cd submod && | |
140 | git config core.worktree >actual && | |
141 | echo "../../../submod" >expect && | |
142 | test_cmp expect actual && | |
143 | rm -f actual expect | |
144 | ) && | |
145 | git submodule init | |
146 | ) && | |
147 | ||
148 | rm -f heads head untracked && | |
149 | inspect addtest/submod ../.. && | |
150 | test_cmp expect heads && | |
151 | test_cmp expect head && | |
152 | test_must_be_empty untracked | |
153 | ' | |
154 | ||
155 | test_expect_success 'setup parent and one repository' ' | |
156 | test_create_repo parent && | |
157 | test_commit -C parent one | |
158 | ' | |
159 | ||
160 | test_expect_success 'redirected submodule add does not show progress' ' | |
161 | git -C addtest submodule add "file://$submodurl/parent" submod-redirected \ | |
162 | 2>err && | |
163 | ! grep % err && | |
164 | test_i18ngrep ! "Checking connectivity" err | |
165 | ' | |
166 | ||
167 | test_expect_success 'redirected submodule add --progress does show progress' ' | |
168 | git -C addtest submodule add --progress "file://$submodurl/parent" \ | |
169 | submod-redirected-progress 2>err && \ | |
170 | grep % err | |
171 | ' | |
172 | ||
173 | test_expect_success 'submodule add to .gitignored path fails' ' | |
174 | ( | |
175 | cd addtest-ignore && | |
176 | cat <<-\EOF >expect && | |
177 | The following paths are ignored by one of your .gitignore files: | |
178 | submod | |
179 | hint: Use -f if you really want to add them. | |
180 | hint: Turn this message off by running | |
181 | hint: "git config advice.addIgnoredFile false" | |
182 | EOF | |
183 | # Does not use test_commit due to the ignore | |
184 | echo "*" > .gitignore && | |
185 | git add --force .gitignore && | |
186 | git commit -m"Ignore everything" && | |
187 | ! git submodule add "$submodurl" submod >actual 2>&1 && | |
188 | test_cmp expect actual | |
189 | ) | |
190 | ' | |
191 | ||
192 | test_expect_success 'submodule add to .gitignored path with --force' ' | |
193 | ( | |
194 | cd addtest-ignore && | |
195 | git submodule add --force "$submodurl" submod | |
196 | ) | |
197 | ' | |
198 | ||
199 | test_expect_success 'submodule add to reconfigure existing submodule with --force' ' | |
200 | ( | |
201 | cd addtest-ignore && | |
202 | bogus_url="$(pwd)/bogus-url" && | |
203 | git submodule add --force "$bogus_url" submod && | |
204 | git submodule add --force -b initial "$submodurl" submod-branch && | |
205 | test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" && | |
206 | test "$bogus_url" = "$(git config submodule.submod.url)" && | |
207 | # Restore the url | |
208 | git submodule add --force "$submodurl" submod && | |
209 | test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" && | |
210 | test "$submodurl" = "$(git config submodule.submod.url)" | |
211 | ) | |
212 | ' | |
213 | ||
214 | test_expect_success 'submodule add relays add --dry-run stderr' ' | |
215 | test_when_finished "rm -rf addtest/.git/index.lock" && | |
216 | ( | |
217 | cd addtest && | |
218 | : >.git/index.lock && | |
219 | ! git submodule add "$submodurl" sub-while-locked 2>output.err && | |
220 | test_i18ngrep "^fatal: .*index\.lock" output.err && | |
221 | test_path_is_missing sub-while-locked | |
222 | ) | |
223 | ' | |
224 | ||
225 | test_expect_success 'submodule add --branch' ' | |
226 | echo "refs/heads/initial" >expect-head && | |
227 | cat <<-\EOF >expect-heads && | |
228 | refs/heads/initial | |
229 | refs/heads/main | |
230 | EOF | |
231 | ||
232 | ( | |
233 | cd addtest && | |
234 | git submodule add -b initial "$submodurl" submod-branch && | |
235 | test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" && | |
236 | git submodule init | |
237 | ) && | |
238 | ||
239 | rm -f heads head untracked && | |
240 | inspect addtest/submod-branch ../.. && | |
241 | test_cmp expect-heads heads && | |
242 | test_cmp expect-head head && | |
243 | test_must_be_empty untracked | |
244 | ' | |
245 | ||
246 | test_expect_success 'submodule add with ./ in path' ' | |
247 | echo "refs/heads/main" >expect && | |
248 | ||
249 | ( | |
250 | cd addtest && | |
251 | git submodule add "$submodurl" ././dotsubmod/./frotz/./ && | |
252 | git submodule init | |
253 | ) && | |
254 | ||
255 | rm -f heads head untracked && | |
256 | inspect addtest/dotsubmod/frotz ../../.. && | |
257 | test_cmp expect heads && | |
258 | test_cmp expect head && | |
259 | test_must_be_empty untracked | |
260 | ' | |
261 | ||
262 | test_expect_success 'submodule add with /././ in path' ' | |
263 | echo "refs/heads/main" >expect && | |
264 | ||
265 | ( | |
266 | cd addtest && | |
267 | git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ && | |
268 | git submodule init | |
269 | ) && | |
270 | ||
271 | rm -f heads head untracked && | |
272 | inspect addtest/dotslashdotsubmod/frotz ../../.. && | |
273 | test_cmp expect heads && | |
274 | test_cmp expect head && | |
275 | test_must_be_empty untracked | |
276 | ' | |
277 | ||
278 | test_expect_success 'submodule add with // in path' ' | |
279 | echo "refs/heads/main" >expect && | |
280 | ||
281 | ( | |
282 | cd addtest && | |
283 | git submodule add "$submodurl" slashslashsubmod///frotz// && | |
284 | git submodule init | |
285 | ) && | |
286 | ||
287 | rm -f heads head untracked && | |
288 | inspect addtest/slashslashsubmod/frotz ../../.. && | |
289 | test_cmp expect heads && | |
290 | test_cmp expect head && | |
291 | test_must_be_empty untracked | |
292 | ' | |
293 | ||
294 | test_expect_success 'submodule add with /.. in path' ' | |
295 | echo "refs/heads/main" >expect && | |
296 | ||
297 | ( | |
298 | cd addtest && | |
299 | git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && | |
300 | git submodule init | |
301 | ) && | |
302 | ||
303 | rm -f heads head untracked && | |
304 | inspect addtest/realsubmod ../.. && | |
305 | test_cmp expect heads && | |
306 | test_cmp expect head && | |
307 | test_must_be_empty untracked | |
308 | ' | |
309 | ||
310 | test_expect_success 'submodule add with ./, /.. and // in path' ' | |
311 | echo "refs/heads/main" >expect && | |
312 | ||
313 | ( | |
314 | cd addtest && | |
315 | git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && | |
316 | git submodule init | |
317 | ) && | |
318 | ||
319 | rm -f heads head untracked && | |
320 | inspect addtest/realsubmod2 ../.. && | |
321 | test_cmp expect heads && | |
322 | test_cmp expect head && | |
323 | test_must_be_empty untracked | |
324 | ' | |
325 | ||
326 | test_expect_success !CYGWIN 'submodule add with \\ in path' ' | |
327 | test_when_finished "rm -rf parent sub\\with\\backslash" && | |
328 | ||
329 | # Initialize a repo with a backslash in its name | |
330 | git init sub\\with\\backslash && | |
331 | touch sub\\with\\backslash/empty.file && | |
332 | git -C sub\\with\\backslash add empty.file && | |
333 | git -C sub\\with\\backslash commit -m "Added empty.file" && | |
334 | ||
335 | # Add that repository as a submodule | |
336 | git init parent && | |
337 | git -C parent submodule add ../sub\\with\\backslash | |
338 | ' | |
339 | ||
340 | test_expect_success 'submodule add in subdirectory' ' | |
341 | echo "refs/heads/main" >expect && | |
342 | ||
343 | mkdir addtest/sub && | |
344 | ( | |
345 | cd addtest/sub && | |
346 | git submodule add "$submodurl" ../realsubmod3 && | |
347 | git submodule init | |
348 | ) && | |
349 | ||
350 | rm -f heads head untracked && | |
351 | inspect addtest/realsubmod3 ../.. && | |
352 | test_cmp expect heads && | |
353 | test_cmp expect head && | |
354 | test_must_be_empty untracked | |
355 | ' | |
356 | ||
357 | test_expect_success 'submodule add in subdirectory with relative path should fail' ' | |
358 | ( | |
359 | cd addtest/sub && | |
360 | test_must_fail git submodule add ../../ submod3 2>../../output.err | |
361 | ) && | |
362 | test_i18ngrep toplevel output.err | |
363 | ' | |
364 | ||
365 | test_expect_success 'setup - add an example entry to .gitmodules' ' | |
366 | git config --file=.gitmodules submodule.example.url git://example.com/init.git | |
367 | ' | |
368 | ||
369 | test_expect_success 'status should fail for unmapped paths' ' | |
370 | test_must_fail git submodule status | |
371 | ' | |
372 | ||
373 | test_expect_success 'setup - map path in .gitmodules' ' | |
374 | cat <<\EOF >expect && | |
375 | [submodule "example"] | |
376 | url = git://example.com/init.git | |
377 | path = init | |
378 | EOF | |
379 | ||
380 | git config --file=.gitmodules submodule.example.path init && | |
381 | ||
382 | test_cmp expect .gitmodules | |
383 | ' | |
384 | ||
385 | test_expect_success 'status should only print one line' ' | |
386 | git submodule status >lines && | |
387 | test_line_count = 1 lines | |
388 | ' | |
389 | ||
390 | test_expect_success 'status from subdirectory should have the same SHA1' ' | |
391 | test_when_finished "rmdir addtest/subdir" && | |
392 | ( | |
393 | cd addtest && | |
394 | mkdir subdir && | |
395 | git submodule status >output && | |
396 | awk "{print \$1}" <output >expect && | |
397 | cd subdir && | |
398 | git submodule status >../output && | |
399 | awk "{print \$1}" <../output >../actual && | |
400 | test_cmp ../expect ../actual && | |
401 | git -C ../submod checkout HEAD^ && | |
402 | git submodule status >../output && | |
403 | awk "{print \$1}" <../output >../actual2 && | |
404 | cd .. && | |
405 | git submodule status >output && | |
406 | awk "{print \$1}" <output >expect2 && | |
407 | test_cmp expect2 actual2 && | |
408 | ! test_cmp actual actual2 | |
409 | ) | |
410 | ' | |
411 | ||
412 | test_expect_success 'setup - fetch commit name from submodule' ' | |
413 | rev1=$(cd .subrepo && git rev-parse HEAD) && | |
414 | printf "rev1: %s\n" "$rev1" && | |
415 | test -n "$rev1" | |
416 | ' | |
417 | ||
418 | test_expect_success 'status should initially be "missing"' ' | |
419 | git submodule status >lines && | |
420 | grep "^-$rev1" lines | |
421 | ' | |
422 | ||
423 | test_expect_success 'init should register submodule url in .git/config' ' | |
424 | echo git://example.com/init.git >expect && | |
425 | ||
426 | git submodule init && | |
427 | git config submodule.example.url >url && | |
428 | git config submodule.example.url ./.subrepo && | |
429 | ||
430 | test_cmp expect url | |
431 | ' | |
432 | ||
433 | test_expect_success 'status should still be "missing" after initializing' ' | |
434 | rm -fr init && | |
435 | mkdir init && | |
436 | git submodule status >lines && | |
437 | rm -fr init && | |
438 | grep "^-$rev1" lines | |
439 | ' | |
440 | ||
441 | test_failure_with_unknown_submodule () { | |
442 | test_must_fail git submodule $1 no-such-submodule 2>output.err && | |
443 | test_i18ngrep "^error: .*no-such-submodule" output.err | |
444 | } | |
445 | ||
446 | test_expect_success 'init should fail with unknown submodule' ' | |
447 | test_failure_with_unknown_submodule init | |
448 | ' | |
449 | ||
450 | test_expect_success 'update should fail with unknown submodule' ' | |
451 | test_failure_with_unknown_submodule update | |
452 | ' | |
453 | ||
454 | test_expect_success 'status should fail with unknown submodule' ' | |
455 | test_failure_with_unknown_submodule status | |
456 | ' | |
457 | ||
458 | test_expect_success 'sync should fail with unknown submodule' ' | |
459 | test_failure_with_unknown_submodule sync | |
460 | ' | |
461 | ||
462 | test_expect_success 'update should fail when path is used by a file' ' | |
463 | echo hello >expect && | |
464 | ||
465 | echo "hello" >init && | |
466 | test_must_fail git submodule update && | |
467 | ||
468 | test_cmp expect init | |
469 | ' | |
470 | ||
471 | test_expect_success 'update should fail when path is used by a nonempty directory' ' | |
472 | echo hello >expect && | |
473 | ||
474 | rm -fr init && | |
475 | mkdir init && | |
476 | echo "hello" >init/a && | |
477 | ||
478 | test_must_fail git submodule update && | |
479 | ||
480 | test_cmp expect init/a | |
481 | ' | |
482 | ||
483 | test_expect_success 'update should work when path is an empty dir' ' | |
484 | rm -fr init && | |
485 | rm -f head-sha1 && | |
486 | echo "$rev1" >expect && | |
487 | ||
488 | mkdir init && | |
489 | git submodule update -q >update.out && | |
490 | test_must_be_empty update.out && | |
491 | ||
492 | inspect init && | |
493 | test_cmp expect head-sha1 | |
494 | ' | |
495 | ||
496 | test_expect_success 'status should be "up-to-date" after update' ' | |
497 | git submodule status >list && | |
498 | grep "^ $rev1" list | |
499 | ' | |
500 | ||
501 | test_expect_success 'status "up-to-date" from subdirectory' ' | |
502 | mkdir -p sub && | |
503 | ( | |
504 | cd sub && | |
505 | git submodule status >../list | |
506 | ) && | |
507 | grep "^ $rev1" list && | |
508 | grep "\\.\\./init" list | |
509 | ' | |
510 | ||
511 | test_expect_success 'status "up-to-date" from subdirectory with path' ' | |
512 | mkdir -p sub && | |
513 | ( | |
514 | cd sub && | |
515 | git submodule status ../init >../list | |
516 | ) && | |
517 | grep "^ $rev1" list && | |
518 | grep "\\.\\./init" list | |
519 | ' | |
520 | ||
521 | test_expect_success 'status should be "modified" after submodule commit' ' | |
522 | ( | |
523 | cd init && | |
524 | echo b >b && | |
525 | git add b && | |
526 | git commit -m "submodule commit 2" | |
527 | ) && | |
528 | ||
529 | rev2=$(cd init && git rev-parse HEAD) && | |
530 | test -n "$rev2" && | |
531 | git submodule status >list && | |
532 | ||
533 | grep "^+$rev2" list | |
534 | ' | |
535 | ||
536 | test_expect_success 'the --cached sha1 should be rev1' ' | |
537 | git submodule --cached status >list && | |
538 | grep "^+$rev1" list | |
539 | ' | |
540 | ||
541 | test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' | |
542 | git diff >diff && | |
543 | grep "^+Subproject commit $rev2" diff | |
544 | ' | |
545 | ||
546 | test_expect_success 'update should checkout rev1' ' | |
547 | rm -f head-sha1 && | |
548 | echo "$rev1" >expect && | |
549 | ||
550 | git submodule update init && | |
551 | inspect init && | |
552 | ||
553 | test_cmp expect head-sha1 | |
554 | ' | |
555 | ||
556 | test_expect_success 'status should be "up-to-date" after update' ' | |
557 | git submodule status >list && | |
558 | grep "^ $rev1" list | |
559 | ' | |
560 | ||
561 | test_expect_success 'checkout superproject with subproject already present' ' | |
562 | git checkout initial && | |
563 | git checkout main | |
564 | ' | |
565 | ||
566 | test_expect_success 'apply submodule diff' ' | |
567 | git branch second && | |
568 | ( | |
569 | cd init && | |
570 | echo s >s && | |
571 | git add s && | |
572 | git commit -m "change subproject" | |
573 | ) && | |
574 | git update-index --add init && | |
575 | git commit -m "change init" && | |
576 | git format-patch -1 --stdout >P.diff && | |
577 | git checkout second && | |
578 | git apply --index P.diff && | |
579 | ||
580 | git diff --cached main >staged && | |
581 | test_must_be_empty staged | |
582 | ' | |
583 | ||
584 | test_expect_success 'update --init' ' | |
585 | mv init init2 && | |
586 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && | |
587 | git config --remove-section submodule.example && | |
588 | test_must_fail git config submodule.example.url && | |
589 | ||
590 | git submodule update init 2> update.out && | |
591 | test_i18ngrep "not initialized" update.out && | |
592 | test_must_fail git rev-parse --resolve-git-dir init/.git && | |
593 | ||
594 | git submodule update --init init && | |
595 | git rev-parse --resolve-git-dir init/.git | |
596 | ' | |
597 | ||
598 | test_expect_success 'update --init from subdirectory' ' | |
599 | mv init init2 && | |
600 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && | |
601 | git config --remove-section submodule.example && | |
602 | test_must_fail git config submodule.example.url && | |
603 | ||
604 | mkdir -p sub && | |
605 | ( | |
606 | cd sub && | |
607 | git submodule update ../init 2>update.out && | |
608 | test_i18ngrep "not initialized" update.out && | |
609 | test_must_fail git rev-parse --resolve-git-dir ../init/.git && | |
610 | ||
611 | git submodule update --init ../init | |
612 | ) && | |
613 | git rev-parse --resolve-git-dir init/.git | |
614 | ' | |
615 | ||
616 | test_expect_success 'do not add files from a submodule' ' | |
617 | ||
618 | git reset --hard && | |
619 | test_must_fail git add init/a | |
620 | ||
621 | ' | |
622 | ||
623 | test_expect_success 'gracefully add/reset submodule with a trailing slash' ' | |
624 | ||
625 | git reset --hard && | |
626 | git commit -m "commit subproject" init && | |
627 | (cd init && | |
628 | echo b > a) && | |
629 | git add init/ && | |
630 | git diff --exit-code --cached init && | |
631 | commit=$(cd init && | |
632 | git commit -m update a >/dev/null && | |
633 | git rev-parse HEAD) && | |
634 | git add init/ && | |
635 | test_must_fail git diff --exit-code --cached init && | |
636 | test $commit = $(git ls-files --stage | | |
637 | sed -n "s/^160000 \([^ ]*\).*/\1/p") && | |
638 | git reset init/ && | |
639 | git diff --exit-code --cached init | |
640 | ||
641 | ' | |
642 | ||
643 | test_expect_success 'ls-files gracefully handles trailing slash' ' | |
644 | ||
645 | test "init" = "$(git ls-files init/)" | |
646 | ||
647 | ' | |
648 | ||
649 | test_expect_success 'moving to a commit without submodule does not leave empty dir' ' | |
650 | rm -rf init && | |
651 | mkdir init && | |
652 | git reset --hard && | |
653 | git checkout initial && | |
654 | test ! -d init && | |
655 | git checkout second | |
656 | ' | |
657 | ||
658 | test_expect_success 'submodule <invalid-subcommand> fails' ' | |
659 | test_must_fail git submodule no-such-subcommand | |
660 | ' | |
661 | ||
662 | test_expect_success 'add submodules without specifying an explicit path' ' | |
663 | mkdir repo && | |
664 | ( | |
665 | cd repo && | |
666 | git init && | |
667 | echo r >r && | |
668 | git add r && | |
669 | git commit -m "repo commit 1" | |
670 | ) && | |
671 | git clone --bare repo/ bare.git && | |
672 | ( | |
673 | cd addtest && | |
674 | git submodule add "$submodurl/repo" && | |
675 | git config -f .gitmodules submodule.repo.path repo && | |
676 | git submodule add "$submodurl/bare.git" && | |
677 | git config -f .gitmodules submodule.bare.path bare | |
678 | ) | |
679 | ' | |
680 | ||
681 | test_expect_success 'add should fail when path is used by a file' ' | |
682 | ( | |
683 | cd addtest && | |
684 | touch file && | |
685 | test_must_fail git submodule add "$submodurl/repo" file | |
686 | ) | |
687 | ' | |
688 | ||
689 | test_expect_success 'add should fail when path is used by an existing directory' ' | |
690 | ( | |
691 | cd addtest && | |
692 | mkdir empty-dir && | |
693 | test_must_fail git submodule add "$submodurl/repo" empty-dir | |
694 | ) | |
695 | ' | |
696 | ||
697 | test_expect_success 'use superproject as upstream when path is relative and no url is set there' ' | |
698 | ( | |
699 | cd addtest && | |
700 | git submodule add ../repo relative && | |
701 | test "$(git config -f .gitmodules submodule.relative.url)" = ../repo && | |
702 | git submodule sync relative && | |
703 | test "$(git config submodule.relative.url)" = "$submodurl/repo" | |
704 | ) | |
705 | ' | |
706 | ||
707 | test_expect_success 'set up for relative path tests' ' | |
708 | mkdir reltest && | |
709 | ( | |
710 | cd reltest && | |
711 | git init && | |
712 | mkdir sub && | |
713 | ( | |
714 | cd sub && | |
715 | git init && | |
716 | test_commit foo | |
717 | ) && | |
718 | git add sub && | |
719 | git config -f .gitmodules submodule.sub.path sub && | |
720 | git config -f .gitmodules submodule.sub.url ../subrepo && | |
721 | cp .git/config pristine-.git-config && | |
722 | cp .gitmodules pristine-.gitmodules | |
723 | ) | |
724 | ' | |
725 | ||
726 | test_expect_success '../subrepo works with URL - ssh://hostname/repo' ' | |
727 | ( | |
728 | cd reltest && | |
729 | cp pristine-.git-config .git/config && | |
730 | cp pristine-.gitmodules .gitmodules && | |
731 | git config remote.origin.url ssh://hostname/repo && | |
732 | git submodule init && | |
733 | test "$(git config submodule.sub.url)" = ssh://hostname/subrepo | |
734 | ) | |
735 | ' | |
736 | ||
737 | test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' ' | |
738 | ( | |
739 | cd reltest && | |
740 | cp pristine-.git-config .git/config && | |
741 | cp pristine-.gitmodules .gitmodules && | |
742 | git config remote.origin.url ssh://hostname:22/repo && | |
743 | git submodule init && | |
744 | test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo | |
745 | ) | |
746 | ' | |
747 | ||
748 | # About the choice of the path in the next test: | |
749 | # - double-slash side-steps path mangling issues on Windows | |
750 | # - it is still an absolute local path | |
751 | # - there cannot be a server with a blank in its name just in case the | |
752 | # path is used erroneously to access a //server/share style path | |
753 | test_expect_success '../subrepo path works with local path - //somewhere else/repo' ' | |
754 | ( | |
755 | cd reltest && | |
756 | cp pristine-.git-config .git/config && | |
757 | cp pristine-.gitmodules .gitmodules && | |
758 | git config remote.origin.url "//somewhere else/repo" && | |
759 | git submodule init && | |
760 | test "$(git config submodule.sub.url)" = "//somewhere else/subrepo" | |
761 | ) | |
762 | ' | |
763 | ||
764 | test_expect_success '../subrepo works with file URL - file:///tmp/repo' ' | |
765 | ( | |
766 | cd reltest && | |
767 | cp pristine-.git-config .git/config && | |
768 | cp pristine-.gitmodules .gitmodules && | |
769 | git config remote.origin.url file:///tmp/repo && | |
770 | git submodule init && | |
771 | test "$(git config submodule.sub.url)" = file:///tmp/subrepo | |
772 | ) | |
773 | ' | |
774 | ||
775 | test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' ' | |
776 | ( | |
777 | cd reltest && | |
778 | cp pristine-.git-config .git/config && | |
779 | cp pristine-.gitmodules .gitmodules && | |
780 | git config remote.origin.url helper:://hostname/repo && | |
781 | git submodule init && | |
782 | test "$(git config submodule.sub.url)" = helper:://hostname/subrepo | |
783 | ) | |
784 | ' | |
785 | ||
786 | test_expect_success '../subrepo works with scp-style URL - user@host:repo' ' | |
787 | ( | |
788 | cd reltest && | |
789 | cp pristine-.git-config .git/config && | |
790 | git config remote.origin.url user@host:repo && | |
791 | git submodule init && | |
792 | test "$(git config submodule.sub.url)" = user@host:subrepo | |
793 | ) | |
794 | ' | |
795 | ||
796 | test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' ' | |
797 | ( | |
798 | cd reltest && | |
799 | cp pristine-.git-config .git/config && | |
800 | cp pristine-.gitmodules .gitmodules && | |
801 | git config remote.origin.url user@host:path/to/repo && | |
802 | git submodule init && | |
803 | test "$(git config submodule.sub.url)" = user@host:path/to/subrepo | |
804 | ) | |
805 | ' | |
806 | ||
807 | test_expect_success '../subrepo works with relative local path - foo' ' | |
808 | ( | |
809 | cd reltest && | |
810 | cp pristine-.git-config .git/config && | |
811 | cp pristine-.gitmodules .gitmodules && | |
812 | git config remote.origin.url foo && | |
813 | # actual: fails with an error | |
814 | git submodule init && | |
815 | test "$(git config submodule.sub.url)" = subrepo | |
816 | ) | |
817 | ' | |
818 | ||
819 | test_expect_success '../subrepo works with relative local path - foo/bar' ' | |
820 | ( | |
821 | cd reltest && | |
822 | cp pristine-.git-config .git/config && | |
823 | cp pristine-.gitmodules .gitmodules && | |
824 | git config remote.origin.url foo/bar && | |
825 | git submodule init && | |
826 | test "$(git config submodule.sub.url)" = foo/subrepo | |
827 | ) | |
828 | ' | |
829 | ||
830 | test_expect_success '../subrepo works with relative local path - ./foo' ' | |
831 | ( | |
832 | cd reltest && | |
833 | cp pristine-.git-config .git/config && | |
834 | cp pristine-.gitmodules .gitmodules && | |
835 | git config remote.origin.url ./foo && | |
836 | git submodule init && | |
837 | test "$(git config submodule.sub.url)" = subrepo | |
838 | ) | |
839 | ' | |
840 | ||
841 | test_expect_success '../subrepo works with relative local path - ./foo/bar' ' | |
842 | ( | |
843 | cd reltest && | |
844 | cp pristine-.git-config .git/config && | |
845 | cp pristine-.gitmodules .gitmodules && | |
846 | git config remote.origin.url ./foo/bar && | |
847 | git submodule init && | |
848 | test "$(git config submodule.sub.url)" = foo/subrepo | |
849 | ) | |
850 | ' | |
851 | ||
852 | test_expect_success '../subrepo works with relative local path - ../foo' ' | |
853 | ( | |
854 | cd reltest && | |
855 | cp pristine-.git-config .git/config && | |
856 | cp pristine-.gitmodules .gitmodules && | |
857 | git config remote.origin.url ../foo && | |
858 | git submodule init && | |
859 | test "$(git config submodule.sub.url)" = ../subrepo | |
860 | ) | |
861 | ' | |
862 | ||
863 | test_expect_success '../subrepo works with relative local path - ../foo/bar' ' | |
864 | ( | |
865 | cd reltest && | |
866 | cp pristine-.git-config .git/config && | |
867 | cp pristine-.gitmodules .gitmodules && | |
868 | git config remote.origin.url ../foo/bar && | |
869 | git submodule init && | |
870 | test "$(git config submodule.sub.url)" = ../foo/subrepo | |
871 | ) | |
872 | ' | |
873 | ||
874 | test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' ' | |
875 | ( | |
876 | cd reltest && | |
877 | cp pristine-.git-config .git/config && | |
878 | cp pristine-.gitmodules .gitmodules && | |
879 | mkdir -p a/b/c && | |
880 | (cd a/b/c && git init && test_commit msg) && | |
881 | git config remote.origin.url ../foo/bar.git && | |
882 | git submodule add ../bar/a/b/c ./a/b/c && | |
883 | git submodule init && | |
884 | test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c | |
885 | ) | |
886 | ' | |
887 | ||
888 | test_expect_success 'moving the superproject does not break submodules' ' | |
889 | ( | |
890 | cd addtest && | |
891 | git submodule status >expect | |
892 | ) && | |
893 | mv addtest addtest2 && | |
894 | ( | |
895 | cd addtest2 && | |
896 | git submodule status >actual && | |
897 | test_cmp expect actual | |
898 | ) | |
899 | ' | |
900 | ||
901 | test_expect_success 'moving the submodule does not break the superproject' ' | |
902 | ( | |
903 | cd addtest2 && | |
904 | git submodule status | |
905 | ) >actual && | |
906 | sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect && | |
907 | mv addtest2/repo addtest2/repo.bak && | |
908 | test_when_finished "mv addtest2/repo.bak addtest2/repo" && | |
909 | ( | |
910 | cd addtest2 && | |
911 | git submodule status | |
912 | ) >actual && | |
913 | test_cmp expect actual | |
914 | ' | |
915 | ||
916 | test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' ' | |
917 | ( | |
918 | cd addtest2 && | |
919 | ( | |
920 | cd repo && | |
921 | echo "$submodurl/repo" >expect && | |
922 | git config remote.origin.url >actual && | |
923 | test_cmp expect actual && | |
924 | echo "gitdir: ../.git/modules/repo" >expect && | |
925 | test_cmp expect .git | |
926 | ) && | |
927 | rm -rf repo && | |
928 | git rm repo && | |
929 | git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual && | |
930 | test_must_be_empty actual && | |
931 | echo "gitdir: ../.git/modules/submod" >expect && | |
932 | test_cmp expect submod/.git && | |
933 | ( | |
934 | cd repo && | |
935 | echo "$submodurl/bare.git" >expect && | |
936 | git config remote.origin.url >actual && | |
937 | test_cmp expect actual && | |
938 | echo "gitdir: ../.git/modules/repo_new" >expect && | |
939 | test_cmp expect .git | |
940 | ) && | |
941 | echo "repo" >expect && | |
942 | test_must_fail git config -f .gitmodules submodule.repo.path && | |
943 | git config -f .gitmodules submodule.repo_new.path >actual && | |
944 | test_cmp expect actual && | |
945 | echo "$submodurl/repo" >expect && | |
946 | test_must_fail git config -f .gitmodules submodule.repo.url && | |
947 | echo "$submodurl/bare.git" >expect && | |
948 | git config -f .gitmodules submodule.repo_new.url >actual && | |
949 | test_cmp expect actual && | |
950 | echo "$submodurl/repo" >expect && | |
951 | git config submodule.repo.url >actual && | |
952 | test_cmp expect actual && | |
953 | echo "$submodurl/bare.git" >expect && | |
954 | git config submodule.repo_new.url >actual && | |
955 | test_cmp expect actual | |
956 | ) | |
957 | ' | |
958 | ||
959 | test_expect_success 'recursive relative submodules stay relative' ' | |
960 | test_when_finished "rm -rf super clone2 subsub sub3" && | |
961 | mkdir subsub && | |
962 | ( | |
963 | cd subsub && | |
964 | git init && | |
965 | >t && | |
966 | git add t && | |
967 | git commit -m "initial commit" | |
968 | ) && | |
969 | mkdir sub3 && | |
970 | ( | |
971 | cd sub3 && | |
972 | git init && | |
973 | >t && | |
974 | git add t && | |
975 | git commit -m "initial commit" && | |
976 | git submodule add ../subsub dirdir/subsub && | |
977 | git commit -m "add submodule subsub" | |
978 | ) && | |
979 | mkdir super && | |
980 | ( | |
981 | cd super && | |
982 | git init && | |
983 | >t && | |
984 | git add t && | |
985 | git commit -m "initial commit" && | |
986 | git submodule add ../sub3 && | |
987 | git commit -m "add submodule sub" | |
988 | ) && | |
989 | git clone super clone2 && | |
990 | ( | |
991 | cd clone2 && | |
992 | git submodule update --init --recursive && | |
993 | echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect && | |
994 | echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect | |
995 | ) && | |
996 | test_cmp clone2/sub3/.git_expect clone2/sub3/.git && | |
997 | test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git | |
998 | ' | |
999 | ||
1000 | test_expect_success 'submodule add with an existing name fails unless forced' ' | |
1001 | ( | |
1002 | cd addtest2 && | |
1003 | rm -rf repo && | |
1004 | git rm repo && | |
1005 | test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo && | |
1006 | test ! -d repo && | |
1007 | test_must_fail git config -f .gitmodules submodule.repo_new.path && | |
1008 | test_must_fail git config -f .gitmodules submodule.repo_new.url && | |
1009 | echo "$submodurl/bare.git" >expect && | |
1010 | git config submodule.repo_new.url >actual && | |
1011 | test_cmp expect actual && | |
1012 | git submodule add -f -q --name repo_new "$submodurl/repo.git" repo && | |
1013 | test -d repo && | |
1014 | echo "repo" >expect && | |
1015 | git config -f .gitmodules submodule.repo_new.path >actual && | |
1016 | test_cmp expect actual && | |
1017 | echo "$submodurl/repo.git" >expect && | |
1018 | git config -f .gitmodules submodule.repo_new.url >actual && | |
1019 | test_cmp expect actual && | |
1020 | echo "$submodurl/repo.git" >expect && | |
1021 | git config submodule.repo_new.url >actual && | |
1022 | test_cmp expect actual | |
1023 | ) | |
1024 | ' | |
1025 | ||
1026 | test_expect_success 'set up a second submodule' ' | |
1027 | git submodule add ./init2 example2 && | |
1028 | git commit -m "submodule example2 added" | |
1029 | ' | |
1030 | ||
1031 | test_expect_success 'submodule deinit works on repository without submodules' ' | |
1032 | test_when_finished "rm -rf newdirectory" && | |
1033 | mkdir newdirectory && | |
1034 | ( | |
1035 | cd newdirectory && | |
1036 | git init && | |
1037 | >file && | |
1038 | git add file && | |
1039 | git commit -m "repo should not be empty" && | |
1040 | git submodule deinit . && | |
1041 | git submodule deinit --all | |
1042 | ) | |
1043 | ' | |
1044 | ||
1045 | test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' ' | |
1046 | git config submodule.example.foo bar && | |
1047 | git config submodule.example2.frotz nitfol && | |
1048 | git submodule deinit init && | |
1049 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1050 | test -n "$(git config --get-regexp "submodule\.example2\.")" && | |
1051 | test -f example2/.git && | |
1052 | rmdir init | |
1053 | ' | |
1054 | ||
1055 | test_expect_success 'submodule deinit should unset core.worktree' ' | |
1056 | test_path_is_file .git/modules/example/config && | |
1057 | test_must_fail git config -f .git/modules/example/config core.worktree | |
1058 | ' | |
1059 | ||
1060 | test_expect_success 'submodule deinit from subdirectory' ' | |
1061 | git submodule update --init && | |
1062 | git config submodule.example.foo bar && | |
1063 | mkdir -p sub && | |
1064 | ( | |
1065 | cd sub && | |
1066 | git submodule deinit ../init >../output | |
1067 | ) && | |
1068 | test_i18ngrep "\\.\\./init" output && | |
1069 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1070 | test -n "$(git config --get-regexp "submodule\.example2\.")" && | |
1071 | test -f example2/.git && | |
1072 | rmdir init | |
1073 | ' | |
1074 | ||
1075 | test_expect_success 'submodule deinit . deinits all initialized submodules' ' | |
1076 | git submodule update --init && | |
1077 | git config submodule.example.foo bar && | |
1078 | git config submodule.example2.frotz nitfol && | |
1079 | test_must_fail git submodule deinit && | |
1080 | git submodule deinit . >actual && | |
1081 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1082 | test -z "$(git config --get-regexp "submodule\.example2\.")" && | |
1083 | test_i18ngrep "Cleared directory .init" actual && | |
1084 | test_i18ngrep "Cleared directory .example2" actual && | |
1085 | rmdir init example2 | |
1086 | ' | |
1087 | ||
1088 | test_expect_success 'submodule deinit --all deinits all initialized submodules' ' | |
1089 | git submodule update --init && | |
1090 | git config submodule.example.foo bar && | |
1091 | git config submodule.example2.frotz nitfol && | |
1092 | test_must_fail git submodule deinit && | |
1093 | git submodule deinit --all >actual && | |
1094 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1095 | test -z "$(git config --get-regexp "submodule\.example2\.")" && | |
1096 | test_i18ngrep "Cleared directory .init" actual && | |
1097 | test_i18ngrep "Cleared directory .example2" actual && | |
1098 | rmdir init example2 | |
1099 | ' | |
1100 | ||
1101 | test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' | |
1102 | git submodule update --init && | |
1103 | rm -rf init example2/* example2/.git && | |
1104 | git submodule deinit init example2 >actual && | |
1105 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1106 | test -z "$(git config --get-regexp "submodule\.example2\.")" && | |
1107 | test_i18ngrep ! "Cleared directory .init" actual && | |
1108 | test_i18ngrep "Cleared directory .example2" actual && | |
1109 | rmdir init | |
1110 | ' | |
1111 | ||
1112 | test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' ' | |
1113 | git submodule update --init && | |
1114 | echo X >>init/s && | |
1115 | test_must_fail git submodule deinit init && | |
1116 | test -n "$(git config --get-regexp "submodule\.example\.")" && | |
1117 | test -f example2/.git && | |
1118 | git submodule deinit -f init >actual && | |
1119 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1120 | test_i18ngrep "Cleared directory .init" actual && | |
1121 | rmdir init | |
1122 | ' | |
1123 | ||
1124 | test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' ' | |
1125 | git submodule update --init && | |
1126 | echo X >>init/untracked && | |
1127 | test_must_fail git submodule deinit init && | |
1128 | test -n "$(git config --get-regexp "submodule\.example\.")" && | |
1129 | test -f example2/.git && | |
1130 | git submodule deinit -f init >actual && | |
1131 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1132 | test_i18ngrep "Cleared directory .init" actual && | |
1133 | rmdir init | |
1134 | ' | |
1135 | ||
1136 | test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' ' | |
1137 | git submodule update --init && | |
1138 | ( | |
1139 | cd init && | |
1140 | git checkout HEAD^ | |
1141 | ) && | |
1142 | test_must_fail git submodule deinit init && | |
1143 | test -n "$(git config --get-regexp "submodule\.example\.")" && | |
1144 | test -f example2/.git && | |
1145 | git submodule deinit -f init >actual && | |
1146 | test -z "$(git config --get-regexp "submodule\.example\.")" && | |
1147 | test_i18ngrep "Cleared directory .init" actual && | |
1148 | rmdir init | |
1149 | ' | |
1150 | ||
1151 | test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' | |
1152 | git submodule update --init && | |
1153 | git submodule deinit init >actual && | |
1154 | test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual && | |
1155 | test_i18ngrep "Cleared directory .init" actual && | |
1156 | git submodule deinit init >actual && | |
1157 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && | |
1158 | test_i18ngrep "Cleared directory .init" actual && | |
1159 | git submodule deinit . >actual && | |
1160 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && | |
1161 | test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual && | |
1162 | test_i18ngrep "Cleared directory .init" actual && | |
1163 | git submodule deinit . >actual && | |
1164 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && | |
1165 | test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && | |
1166 | test_i18ngrep "Cleared directory .init" actual && | |
1167 | git submodule deinit --all >actual && | |
1168 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && | |
1169 | test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && | |
1170 | test_i18ngrep "Cleared directory .init" actual && | |
1171 | rmdir init example2 | |
1172 | ' | |
1173 | ||
1174 | test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' | |
1175 | git submodule update --init && | |
1176 | ( | |
1177 | cd init && | |
1178 | rm .git && | |
1179 | cp -R ../.git/modules/example .git && | |
1180 | GIT_WORK_TREE=. git config --unset core.worktree | |
1181 | ) && | |
1182 | test_must_fail git submodule deinit init && | |
1183 | test_must_fail git submodule deinit -f init && | |
1184 | test -d init/.git && | |
1185 | test -n "$(git config --get-regexp "submodule\.example\.")" | |
1186 | ' | |
1187 | ||
1188 | test_expect_success 'submodule with UTF-8 name' ' | |
1189 | svname=$(printf "\303\245 \303\244\303\266") && | |
1190 | mkdir "$svname" && | |
1191 | ( | |
1192 | cd "$svname" && | |
1193 | git init && | |
1194 | >sub && | |
1195 | git add sub && | |
1196 | git commit -m "init sub" | |
1197 | ) && | |
1198 | git submodule add ./"$svname" && | |
1199 | git submodule >&2 && | |
1200 | test -n "$(git submodule | grep "$svname")" | |
1201 | ' | |
1202 | ||
1203 | test_expect_success 'submodule add clone shallow submodule' ' | |
1204 | mkdir super && | |
1205 | pwd=$(pwd) && | |
1206 | ( | |
1207 | cd super && | |
1208 | git init && | |
1209 | git submodule add --depth=1 file://"$pwd"/example2 submodule && | |
1210 | ( | |
1211 | cd submodule && | |
1212 | test 1 = $(git log --oneline | wc -l) | |
1213 | ) | |
1214 | ) | |
1215 | ' | |
1216 | ||
1217 | test_expect_success 'submodule helper list is not confused by common prefixes' ' | |
1218 | mkdir -p dir1/b && | |
1219 | ( | |
1220 | cd dir1/b && | |
1221 | git init && | |
1222 | echo hi >testfile2 && | |
1223 | git add . && | |
1224 | git commit -m "test1" | |
1225 | ) && | |
1226 | mkdir -p dir2/b && | |
1227 | ( | |
1228 | cd dir2/b && | |
1229 | git init && | |
1230 | echo hello >testfile1 && | |
1231 | git add . && | |
1232 | git commit -m "test2" | |
1233 | ) && | |
1234 | git submodule add /dir1/b dir1/b && | |
1235 | git submodule add /dir2/b dir2/b && | |
1236 | git commit -m "first submodule commit" && | |
1237 | git submodule--helper list dir1/b | cut -f 2 >actual && | |
1238 | echo "dir1/b" >expect && | |
1239 | test_cmp expect actual | |
1240 | ' | |
1241 | ||
1242 | test_expect_success 'setup superproject with submodules' ' | |
1243 | git init sub1 && | |
1244 | test_commit -C sub1 test && | |
1245 | test_commit -C sub1 test2 && | |
1246 | git init multisuper && | |
1247 | git -C multisuper submodule add ../sub1 sub0 && | |
1248 | git -C multisuper submodule add ../sub1 sub1 && | |
1249 | git -C multisuper submodule add ../sub1 sub2 && | |
1250 | git -C multisuper submodule add ../sub1 sub3 && | |
1251 | git -C multisuper commit -m "add some submodules" | |
1252 | ' | |
1253 | ||
1254 | cat >expect <<-EOF | |
1255 | -sub0 | |
1256 | sub1 (test2) | |
1257 | sub2 (test2) | |
1258 | sub3 (test2) | |
1259 | EOF | |
1260 | ||
1261 | test_expect_success 'submodule update --init with a specification' ' | |
1262 | test_when_finished "rm -rf multisuper_clone" && | |
1263 | pwd=$(pwd) && | |
1264 | git clone file://"$pwd"/multisuper multisuper_clone && | |
1265 | git -C multisuper_clone submodule update --init . ":(exclude)sub0" && | |
1266 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1267 | test_cmp expect actual | |
1268 | ' | |
1269 | ||
1270 | test_expect_success 'submodule update --init with submodule.active set' ' | |
1271 | test_when_finished "rm -rf multisuper_clone" && | |
1272 | pwd=$(pwd) && | |
1273 | git clone file://"$pwd"/multisuper multisuper_clone && | |
1274 | git -C multisuper_clone config submodule.active "." && | |
1275 | git -C multisuper_clone config --add submodule.active ":(exclude)sub0" && | |
1276 | git -C multisuper_clone submodule update --init && | |
1277 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1278 | test_cmp expect actual | |
1279 | ' | |
1280 | ||
1281 | test_expect_success 'submodule update and setting submodule.<name>.active' ' | |
1282 | test_when_finished "rm -rf multisuper_clone" && | |
1283 | pwd=$(pwd) && | |
1284 | git clone file://"$pwd"/multisuper multisuper_clone && | |
1285 | git -C multisuper_clone config --bool submodule.sub0.active "true" && | |
1286 | git -C multisuper_clone config --bool submodule.sub1.active "false" && | |
1287 | git -C multisuper_clone config --bool submodule.sub2.active "true" && | |
1288 | ||
1289 | cat >expect <<-\EOF && | |
1290 | sub0 (test2) | |
1291 | -sub1 | |
1292 | sub2 (test2) | |
1293 | -sub3 | |
1294 | EOF | |
1295 | git -C multisuper_clone submodule update && | |
1296 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1297 | test_cmp expect actual | |
1298 | ' | |
1299 | ||
1300 | test_expect_success 'clone active submodule without submodule url set' ' | |
1301 | test_when_finished "rm -rf test/test" && | |
1302 | mkdir test && | |
1303 | # another dir breaks accidental relative paths still being correct | |
1304 | git clone file://"$pwd"/multisuper test/test && | |
1305 | ( | |
1306 | cd test/test && | |
1307 | git config submodule.active "." && | |
1308 | ||
1309 | # do not pass --init flag, as the submodule is already active: | |
1310 | git submodule update && | |
1311 | git submodule status >actual_raw && | |
1312 | ||
1313 | cut -d" " -f3- actual_raw >actual && | |
1314 | cat >expect <<-\EOF && | |
1315 | sub0 (test2) | |
1316 | sub1 (test2) | |
1317 | sub2 (test2) | |
1318 | sub3 (test2) | |
1319 | EOF | |
1320 | test_cmp expect actual | |
1321 | ) | |
1322 | ' | |
1323 | ||
1324 | test_expect_success 'clone --recurse-submodules with a pathspec works' ' | |
1325 | test_when_finished "rm -rf multisuper_clone" && | |
1326 | cat >expected <<-\EOF && | |
1327 | sub0 (test2) | |
1328 | -sub1 | |
1329 | -sub2 | |
1330 | -sub3 | |
1331 | EOF | |
1332 | ||
1333 | git clone --recurse-submodules="sub0" multisuper multisuper_clone && | |
1334 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1335 | test_cmp expected actual | |
1336 | ' | |
1337 | ||
1338 | test_expect_success 'clone with multiple --recurse-submodules options' ' | |
1339 | test_when_finished "rm -rf multisuper_clone" && | |
1340 | cat >expect <<-\EOF && | |
1341 | -sub0 | |
1342 | sub1 (test2) | |
1343 | -sub2 | |
1344 | sub3 (test2) | |
1345 | EOF | |
1346 | ||
1347 | git clone --recurse-submodules="." \ | |
1348 | --recurse-submodules=":(exclude)sub0" \ | |
1349 | --recurse-submodules=":(exclude)sub2" \ | |
1350 | multisuper multisuper_clone && | |
1351 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1352 | test_cmp expect actual | |
1353 | ' | |
1354 | ||
1355 | test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' ' | |
1356 | test_when_finished "rm -rf multisuper_clone" && | |
1357 | cat <<-\EOF >expect && | |
1358 | -sub0 | |
1359 | sub1 (test2) | |
1360 | -sub2 | |
1361 | sub3 (test2) | |
1362 | EOF | |
1363 | ||
1364 | cat <<-\EOF >expect2 && | |
1365 | -sub0 | |
1366 | sub1 (test2) | |
1367 | -sub2 | |
1368 | sub3 (test2) | |
1369 | -sub4 | |
1370 | sub5 (test2) | |
1371 | EOF | |
1372 | ||
1373 | git clone --recurse-submodules="." \ | |
1374 | --recurse-submodules=":(exclude)sub0" \ | |
1375 | --recurse-submodules=":(exclude)sub2" \ | |
1376 | --recurse-submodules=":(exclude)sub4" \ | |
1377 | multisuper multisuper_clone && | |
1378 | ||
1379 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1380 | test_cmp expect actual && | |
1381 | ||
1382 | git -C multisuper submodule add ../sub1 sub4 && | |
1383 | git -C multisuper submodule add ../sub1 sub5 && | |
1384 | git -C multisuper commit -m "add more submodules" && | |
1385 | # obtain the new superproject | |
1386 | git -C multisuper_clone pull && | |
1387 | git -C multisuper_clone submodule update --init && | |
1388 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && | |
1389 | test_cmp expect2 actual | |
1390 | ' | |
1391 | ||
1392 | test_expect_success 'init properly sets the config' ' | |
1393 | test_when_finished "rm -rf multisuper_clone" && | |
1394 | git clone --recurse-submodules="." \ | |
1395 | --recurse-submodules=":(exclude)sub0" \ | |
1396 | multisuper multisuper_clone && | |
1397 | ||
1398 | git -C multisuper_clone submodule init -- sub0 sub1 && | |
1399 | git -C multisuper_clone config --get submodule.sub0.active && | |
1400 | test_must_fail git -C multisuper_clone config --get submodule.sub1.active | |
1401 | ' | |
1402 | ||
1403 | test_expect_success 'recursive clone respects -q' ' | |
1404 | test_when_finished "rm -rf multisuper_clone" && | |
1405 | git clone -q --recurse-submodules multisuper multisuper_clone >actual && | |
1406 | test_must_be_empty actual | |
1407 | ' | |
1408 | ||
1409 | test_done |