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