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