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