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