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