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