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