blob: 981488885fba49c57176b8d5054b06ac6bb8f4bc [file] [log] [blame]
Lars Hjemli88961ef2007-06-02 03:27:42 +02001#!/bin/sh
2#
3# Copyright (c) 2007 Lars Hjemli
4#
5
6test_description='Basic porcelain support for submodules
7
8This test tries to verify basic sanity of the init, update and status
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09009subcommands of git submodule.
Lars Hjemli88961ef2007-06-02 03:27:42 +020010'
11
Johannes Schindelin01dc8132020-11-18 23:44:39 +000012GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +000013export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14
Lars Hjemli88961ef2007-06-02 03:27:42 +020015. ./test-lib.sh
16
Taylor Blau0d3beb72022-07-29 15:21:40 -040017test_expect_success 'setup - enable local submodules' '
18 git config --global protocol.file.allow always
19'
20
Ævar Arnfjörð Bjarmason89bc7b52022-09-01 01:17:43 +020021test_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
27test_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
33test_expect_success 'submodule usage: status --' '
34 test_expect_code 1 git submodule -- &&
35 test_expect_code 1 git submodule --end-of-options
36'
37
38for opt in '--quiet' '--cached'
39do
40 test_expect_success "submodule usage: status $opt" '
41 git submodule $opt &&
42 git submodule status $opt &&
43 git submodule $opt status
44 '
45done
46
Stefan Bellerf6a52792016-05-05 12:52:32 -070047test_expect_success 'submodule deinit works on empty repository' '
48 git submodule deinit --all
49'
50
Jonathan Niederfe454b12010-04-10 00:38:37 -050051test_expect_success 'setup - initial commit' '
52 >t &&
Nanako Shiraishi47a528a2008-09-03 17:59:33 +090053 git add t &&
54 git commit -m "initial commit" &&
Jonathan Niederfe454b12010-04-10 00:38:37 -050055 git branch initial
56'
57
Stefan Bellerd92028a2016-04-28 13:02:45 -070058test_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 &&
Junio C Hamano67892752023-10-31 14:23:30 +090063 test_grep "No url found for submodule path" actual
Stefan Bellerd92028a2016-04-28 13:02:45 -070064'
65
Stefan Beller08fdbdb2016-04-28 13:02:46 -070066test_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 &&
Junio C Hamano67892752023-10-31 14:23:30 +090071 test_grep "Submodule path .sub. not initialized" actual
Stefan Beller08fdbdb2016-04-28 13:02:46 -070072'
73
Jeff King627fde12017-04-24 20:57:47 -040074test_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
Kyle Meyere1381112019-04-09 19:07:35 -040082test_expect_success 'add aborts on repository with no commits' '
83 cat >expect <<-\EOF &&
Atharva Raykar0008d122021-07-10 13:17:59 +053084 fatal: '"'repo-no-commits'"' does not have a commit checked out
Kyle Meyere1381112019-04-09 19:07:35 -040085 EOF
86 git init repo-no-commits &&
87 test_must_fail git submodule add ../a ./repo-no-commits 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010088 test_cmp expect actual
Kyle Meyere1381112019-04-09 19:07:35 -040089'
90
Peter Kaestlef38c9242020-02-03 00:32:44 +010091test_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 &&
Junio C Hamano67892752023-10-31 14:23:30 +0900103 test_grep "^error: .*did not match any file(s) known to git" output.err
Peter Kaestlef38c9242020-02-03 00:32:44 +0100104'
105
Jonathan Niederfe454b12010-04-10 00:38:37 -0500106test_expect_success 'setup - repository in init subdirectory' '
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800107 mkdir init &&
Jonathan Niederfe454b12010-04-10 00:38:37 -0500108 (
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 )
Jonathan Niederfe454b12010-04-10 00:38:37 -0500116'
117
118test_expect_success 'setup - commit with gitlink' '
Lars Hjemli88961ef2007-06-02 03:27:42 +0200119 echo a >a &&
120 echo z >z &&
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800121 git add a init z &&
Jonathan Niederfe454b12010-04-10 00:38:37 -0500122 git commit -m "super commit 1"
123'
124
125test_expect_success 'setup - hide init subdirectory' '
126 mv init .subrepo
127'
128
Jonathan Niedera76c9442010-04-10 00:39:04 -0500129test_expect_success 'setup - repository to add submodules to' '
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000130 git init addtest &&
131 git init addtest-ignore
Michael J Gruberac8463d2009-03-03 16:08:20 +0100132'
133
Jonathan Niedera76c9442010-04-10 00:39:04 -0500134# The 'submodule add' tests need some repository to add as a submodule.
Jeff Kingdd008b32011-07-30 09:05:54 -0600135# 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.
138submodurl=$(pwd -P)
Jonathan Niedera76c9442010-04-10 00:39:04 -0500139
140listbranches() {
141 git for-each-ref --format='%(refname)' 'refs/heads/*'
142}
143
144inspect() {
145 dir=$1 &&
146 dotdot="${2:-..}" &&
147
148 (
149 cd "$dir" &&
150 listbranches >"$dotdot/heads" &&
151 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500152 git rev-parse HEAD >"$dotdot/head-sha1" &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500153 git update-index --refresh &&
154 git diff-files --exit-code &&
155 git clean -n -d -x >"$dotdot/untracked"
156 )
157}
158
Michael J Gruberac8463d2009-03-03 16:08:20 +0100159test_expect_success 'submodule add' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000160 echo "refs/heads/main" >expect &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500161
Michael J Gruberac8463d2009-03-03 16:08:20 +0100162 (
163 cd addtest &&
Jens Lehmann7e604072011-07-26 23:39:03 +0200164 git submodule add -q "$submodurl" submod >actual &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700165 test_must_be_empty actual &&
Jens Lehmannea115a02012-03-04 22:14:30 +0100166 echo "gitdir: ../.git/modules/submod" >expect &&
167 test_cmp expect submod/.git &&
Jens Lehmannd75219b2012-03-04 22:15:08 +0100168 (
169 cd submod &&
170 git config core.worktree >actual &&
171 echo "../../../submod" >expect &&
172 test_cmp expect actual &&
173 rm -f actual expect
174 ) &&
Michael J Gruberac8463d2009-03-03 16:08:20 +0100175 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500176 ) &&
177
178 rm -f heads head untracked &&
179 inspect addtest/submod ../.. &&
180 test_cmp expect heads &&
181 test_cmp expect head &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200182 test_must_be_empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100183'
184
Ævar Arnfjörð Bjarmason59378e32022-09-01 01:17:44 +0200185test_expect_success !WINDOWS 'submodule add (absolute path)' '
186 test_when_finished "git reset --hard" &&
187 git submodule add "$submodurl" "$submodurl/add-abs"
188'
189
Stefan Beller83f5fa52018-06-18 16:41:48 -0700190test_expect_success 'setup parent and one repository' '
191 test_create_repo parent &&
192 test_commit -C parent one
193'
Casey Fitzpatrick6d33e1c2018-05-03 06:53:45 -0400194
195test_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 &&
Junio C Hamano67892752023-10-31 14:23:30 +0900199 test_grep ! "Checking connectivity" err
Casey Fitzpatrick6d33e1c2018-05-03 06:53:45 -0400200'
201
202test_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
Jens Lehmannd27b8762010-07-17 17:11:43 +0200208test_expect_success 'submodule add to .gitignored path fails' '
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000209 (
210 cd addtest-ignore &&
Jens Lehmannd27b8762010-07-17 17:11:43 +0200211 cat <<-\EOF >expect &&
Kyle Meyerc8163852020-01-07 19:31:21 -0500212 The following paths are ignored by one of your .gitignore files:
Jens Lehmannd27b8762010-07-17 17:11:43 +0200213 submod
Junio C Hamanodaef1b32020-02-14 12:54:19 -0800214 hint: Use -f if you really want to add them.
Rubén Justo9da49be2024-03-30 15:07:27 +0100215 hint: Disable this message with "git config advice.addIgnoredFile false"
Jens Lehmannd27b8762010-07-17 17:11:43 +0200216 EOF
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000217 # Does not use test_commit due to the ignore
218 echo "*" > .gitignore &&
219 git add --force .gitignore &&
220 git commit -m"Ignore everything" &&
Jens Lehmannd27b8762010-07-17 17:11:43 +0200221 ! git submodule add "$submodurl" submod >actual 2>&1 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100222 test_cmp expect actual
Jens Lehmannd27b8762010-07-17 17:11:43 +0200223 )
224'
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000225
Jens Lehmannd27b8762010-07-17 17:11:43 +0200226test_expect_success 'submodule add to .gitignored path with --force' '
227 (
228 cd addtest-ignore &&
229 git submodule add --force "$submodurl" submod
230 )
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000231'
232
Atharva Raykar84069fc2021-07-06 23:49:34 +0530233test_expect_success 'submodule add to path with tracked content fails' '
234 (
235 cd addtest &&
Atharva Raykar0008d122021-07-10 13:17:59 +0530236 echo "fatal: '\''dir-tracked'\'' already exists in the index" >expect &&
Atharva Raykar84069fc2021-07-06 23:49:34 +0530237 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
Stefan Beller619acfc2016-10-06 12:37:24 -0700244test_expect_success 'submodule add to reconfigure existing submodule with --force' '
245 (
246 cd addtest-ignore &&
Eric Sunshineadc73312018-07-01 20:23:51 -0400247 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)" &&
Stefan Beller619acfc2016-10-06 12:37:24 -0700252 # Restore the url
Eric Sunshineadc73312018-07-01 20:23:51 -0400253 git submodule add --force "$submodurl" submod &&
Stefan Beller619acfc2016-10-06 12:37:24 -0700254 test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
255 test "$submodurl" = "$(git config submodule.submod.url)"
256 )
257'
258
Kyle Meyerc8163852020-01-07 19:31:21 -0500259test_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 &&
Junio C Hamano67892752023-10-31 14:23:30 +0900265 test_grep "^fatal: .*index\.lock" output.err &&
Kyle Meyerc8163852020-01-07 19:31:21 -0500266 test_path_is_missing sub-while-locked
267 )
268'
269
Ben Jacksonea10b602009-04-18 20:42:07 -0700270test_expect_success 'submodule add --branch' '
Jonathan Niedera76c9442010-04-10 00:39:04 -0500271 echo "refs/heads/initial" >expect-head &&
272 cat <<-\EOF >expect-heads &&
273 refs/heads/initial
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000274 refs/heads/main
Jonathan Niedera76c9442010-04-10 00:39:04 -0500275 EOF
Jonathan Niedera76c9442010-04-10 00:39:04 -0500276
Ben Jacksonea10b602009-04-18 20:42:07 -0700277 (
278 cd addtest &&
279 git submodule add -b initial "$submodurl" submod-branch &&
W. Trevor Kingb9289222012-12-19 11:03:33 -0500280 test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500281 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 &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200288 test_must_be_empty untracked
Ben Jacksonea10b602009-04-18 20:42:07 -0700289'
290
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100291test_expect_success 'submodule add with ./ in path' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000292 echo "refs/heads/main" >expect &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500293
Michael J Gruberac8463d2009-03-03 16:08:20 +0100294 (
295 cd addtest &&
296 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
297 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500298 ) &&
299
300 rm -f heads head untracked &&
301 inspect addtest/dotsubmod/frotz ../../.. &&
302 test_cmp expect heads &&
303 test_cmp expect head &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200304 test_must_be_empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100305'
306
Patrick Steinhardt8196e722015-01-30 16:14:03 +0100307test_expect_success 'submodule add with /././ in path' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000308 echo "refs/heads/main" >expect &&
Patrick Steinhardt8196e722015-01-30 16:14:03 +0100309
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 &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200320 test_must_be_empty untracked
Patrick Steinhardt8196e722015-01-30 16:14:03 +0100321'
322
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100323test_expect_success 'submodule add with // in path' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000324 echo "refs/heads/main" >expect &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500325
Michael J Gruberac8463d2009-03-03 16:08:20 +0100326 (
327 cd addtest &&
328 git submodule add "$submodurl" slashslashsubmod///frotz// &&
329 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500330 ) &&
331
332 rm -f heads head untracked &&
333 inspect addtest/slashslashsubmod/frotz ../../.. &&
334 test_cmp expect heads &&
335 test_cmp expect head &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200336 test_must_be_empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100337'
338
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100339test_expect_success 'submodule add with /.. in path' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000340 echo "refs/heads/main" >expect &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500341
Michael J Gruberac8463d2009-03-03 16:08:20 +0100342 (
343 cd addtest &&
344 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
345 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500346 ) &&
347
348 rm -f heads head untracked &&
349 inspect addtest/realsubmod ../.. &&
350 test_cmp expect heads &&
351 test_cmp expect head &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200352 test_must_be_empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100353'
354
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100355test_expect_success 'submodule add with ./, /.. and // in path' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000356 echo "refs/heads/main" >expect &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500357
Michael J Gruberac8463d2009-03-03 16:08:20 +0100358 (
359 cd addtest &&
360 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
361 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500362 ) &&
363
364 rm -f heads head untracked &&
365 inspect addtest/realsubmod2 ../.. &&
366 test_cmp expect heads &&
367 test_cmp expect head &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200368 test_must_be_empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100369'
370
Ramsay Jones7f1b2252017-04-30 18:29:30 +0100371test_expect_success !CYGWIN 'submodule add with \\ in path' '
Brandon Williamscf9e55f2017-04-07 10:23:06 -0700372 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
John Keeping091a6eb2013-06-16 15:18:18 +0100385test_expect_success 'submodule add in subdirectory' '
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000386 echo "refs/heads/main" >expect &&
John Keeping091a6eb2013-06-16 15:18:18 +0100387
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 &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200399 test_must_be_empty untracked
John Keeping091a6eb2013-06-16 15:18:18 +0100400'
401
402test_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 ) &&
Junio C Hamano67892752023-10-31 14:23:30 +0900407 test_grep toplevel output.err
John Keeping091a6eb2013-06-16 15:18:18 +0100408'
409
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500410test_expect_success 'setup - add an example entry to .gitmodules' '
Jeff Kingf7e87142014-03-20 19:17:01 -0400411 git config --file=.gitmodules submodule.example.url git://example.com/init.git
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500412'
413
Lars Hjemli941987a2007-06-11 21:12:24 +0200414test_expect_success 'status should fail for unmapped paths' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500415 test_must_fail git submodule status
416'
417
418test_expect_success 'setup - map path in .gitmodules' '
419 cat <<\EOF >expect &&
420[submodule "example"]
421 url = git://example.com/init.git
422 path = init
423EOF
424
Jeff Kingf7e87142014-03-20 19:17:01 -0400425 git config --file=.gitmodules submodule.example.path init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500426
427 test_cmp expect .gitmodules
Lars Hjemli88961ef2007-06-02 03:27:42 +0200428'
429
430test_expect_success 'status should only print one line' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500431 git submodule status >lines &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200432 test_line_count = 1 lines
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500433'
434
Manish Goregaokar1f3aea22019-11-25 04:15:44 +0000435test_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
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500457test_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"
Lars Hjemli88961ef2007-06-02 03:27:42 +0200461'
462
463test_expect_success 'status should initially be "missing"' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500464 git submodule status >lines &&
465 grep "^-$rev1" lines
Lars Hjemli88961ef2007-06-02 03:27:42 +0200466'
467
Lars Hjemli211b7f12007-06-06 11:13:02 +0200468test_expect_success 'init should register submodule url in .git/config' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500469 echo git://example.com/init.git >expect &&
470
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900471 git submodule init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500472 git config submodule.example.url >url &&
473 git config submodule.example.url ./.subrepo &&
474
475 test_cmp expect url
Lars Hjemli211b7f12007-06-06 11:13:02 +0200476'
477
Peter Kaestle3b2885e2020-01-24 11:34:04 +0100478test_expect_success 'status should still be "missing" after initializing' '
Peter Kaestleace912b2020-01-24 11:34:03 +0100479 rm -fr init &&
480 mkdir init &&
481 git submodule status >lines &&
482 rm -fr init &&
483 grep "^-$rev1" lines
484'
485
Heiko Voigtbe9d0a32012-08-14 22:35:27 +0200486test_failure_with_unknown_submodule () {
487 test_must_fail git submodule $1 no-such-submodule 2>output.err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900488 test_grep "^error: .*no-such-submodule" output.err
Heiko Voigtbe9d0a32012-08-14 22:35:27 +0200489}
490
491test_expect_success 'init should fail with unknown submodule' '
492 test_failure_with_unknown_submodule init
493'
494
495test_expect_success 'update should fail with unknown submodule' '
496 test_failure_with_unknown_submodule update
497'
498
499test_expect_success 'status should fail with unknown submodule' '
500 test_failure_with_unknown_submodule status
501'
502
503test_expect_success 'sync should fail with unknown submodule' '
504 test_failure_with_unknown_submodule sync
505'
506
Lars Hjemli211b7f12007-06-06 11:13:02 +0200507test_expect_success 'update should fail when path is used by a file' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500508 echo hello >expect &&
509
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800510 echo "hello" >init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500511 test_must_fail git submodule update &&
512
513 test_cmp expect init
Lars Hjemli88961ef2007-06-02 03:27:42 +0200514'
515
Lars Hjemli211b7f12007-06-06 11:13:02 +0200516test_expect_success 'update should fail when path is used by a nonempty directory' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500517 echo hello >expect &&
518
519 rm -fr init &&
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800520 mkdir init &&
521 echo "hello" >init/a &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500522
523 test_must_fail git submodule update &&
524
525 test_cmp expect init/a
Lars Hjemli88961ef2007-06-02 03:27:42 +0200526'
527
Lars Hjemli211b7f12007-06-06 11:13:02 +0200528test_expect_success 'update should work when path is an empty dir' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500529 rm -fr init &&
530 rm -f head-sha1 &&
531 echo "$rev1" >expect &&
532
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800533 mkdir init &&
Jens Lehmann7e604072011-07-26 23:39:03 +0200534 git submodule update -q >update.out &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700535 test_must_be_empty update.out &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500536
537 inspect init &&
538 test_cmp expect head-sha1
Lars Hjemli88961ef2007-06-02 03:27:42 +0200539'
540
Lars Hjemli211b7f12007-06-06 11:13:02 +0200541test_expect_success 'status should be "up-to-date" after update' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500542 git submodule status >list &&
543 grep "^ $rev1" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200544'
545
John Keeping091a6eb2013-06-16 15:18:18 +0100546test_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
556test_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
Lars Hjemli88961ef2007-06-02 03:27:42 +0200566test_expect_success 'status should be "modified" after submodule commit' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500567 (
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
Lars Hjemli88961ef2007-06-02 03:27:42 +0200579'
580
Ævar Arnfjörð Bjarmason44874cb2022-11-08 15:10:33 +0100581test_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
Lars Hjemli88961ef2007-06-02 03:27:42 +0200591test_expect_success 'the --cached sha1 should be rev1' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500592 git submodule --cached status >list &&
593 grep "^+$rev1" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200594'
595
Sven Verdoolaege57011152007-09-08 12:30:22 +0200596test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500597 git diff >diff &&
598 grep "^+Subproject commit $rev2" diff
Sven Verdoolaege57011152007-09-08 12:30:22 +0200599'
600
Lars Hjemli88961ef2007-06-02 03:27:42 +0200601test_expect_success 'update should checkout rev1' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500602 rm -f head-sha1 &&
603 echo "$rev1" >expect &&
604
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900605 git submodule update init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500606 inspect init &&
607
608 test_cmp expect head-sha1
Lars Hjemli88961ef2007-06-02 03:27:42 +0200609'
610
611test_expect_success 'status should be "up-to-date" after update' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500612 git submodule status >list &&
613 grep "^ $rev1" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200614'
615
Sven Verdoolaege0cf73752007-07-17 20:28:28 +0200616test_expect_success 'checkout superproject with subproject already present' '
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900617 git checkout initial &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000618 git checkout main
Sven Verdoolaege0cf73752007-07-17 20:28:28 +0200619'
620
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200621test_expect_success 'apply submodule diff' '
622 git branch second &&
623 (
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800624 cd init &&
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200625 echo s >s &&
626 git add s &&
627 git commit -m "change subproject"
628 ) &&
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800629 git update-index --add init &&
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900630 git commit -m "change init" &&
631 git format-patch -1 --stdout >P.diff &&
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200632 git checkout second &&
633 git apply --index P.diff &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500634
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000635 git diff --cached main >staged &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200636 test_must_be_empty staged
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200637'
638
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100639test_expect_success 'update --init' '
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100640 mv init init2 &&
641 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500642 git config --remove-section submodule.example &&
643 test_must_fail git config submodule.example.url &&
644
Stefan Beller8c6b5492016-02-29 18:07:14 -0800645 git submodule update init 2> update.out &&
Junio C Hamano67892752023-10-31 14:23:30 +0900646 test_grep "not initialized" update.out &&
Fredrik Gustafssonabc06822011-08-15 23:17:46 +0200647 test_must_fail git rev-parse --resolve-git-dir init/.git &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500648
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100649 git submodule update --init init &&
Fredrik Gustafssonabc06822011-08-15 23:17:46 +0200650 git rev-parse --resolve-git-dir init/.git
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100651'
652
John Keeping091a6eb2013-06-16 15:18:18 +0100653test_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 &&
Stefan Beller8c6b5492016-02-29 18:07:14 -0800662 git submodule update ../init 2>update.out &&
Junio C Hamano67892752023-10-31 14:23:30 +0900663 test_grep "not initialized" update.out &&
John Keeping091a6eb2013-06-16 15:18:18 +0100664 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
Johannes Schindelin2ce53f92009-01-02 19:08:40 +0100671test_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
John Keeping2c63d6e2013-09-12 20:25:01 +0100678test_expect_success 'gracefully add/reset submodule with a trailing slash' '
Johannes Schindelin2ce53f92009-01-02 19:08:40 +0100679
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 |
John Keeping2c63d6e2013-09-12 20:25:01 +0100692 sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
693 git reset init/ &&
694 git diff --exit-code --cached init
Johannes Schindelin2ce53f92009-01-02 19:08:40 +0100695
696'
697
Johannes Schindelinf3670a52009-02-07 14:43:03 +0100698test_expect_success 'ls-files gracefully handles trailing slash' '
699
700 test "init" = "$(git ls-files init/)"
701
702'
703
Peter Collingbournec5e558a2010-01-11 02:59:54 +0000704test_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
Ramkumar Ramachandraaf9c9f92012-09-22 16:57:59 +0530713test_expect_success 'submodule <invalid-subcommand> fails' '
714 test_must_fail git submodule no-such-subcommand
Johannes Schindelin496917b2009-02-07 14:43:15 +0100715'
716
Jens Lehmann1414e572009-09-22 17:10:12 +0200717test_expect_success 'add submodules without specifying an explicit path' '
718 mkdir repo &&
Jonathan Nieder18a82692010-09-06 20:42:54 -0500719 (
720 cd repo &&
721 git init &&
722 echo r >r &&
723 git add r &&
724 git commit -m "repo commit 1"
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +0200725 ) &&
Jens Lehmann1414e572009-09-22 17:10:12 +0200726 git clone --bare repo/ bare.git &&
Jens Lehmann69e72362010-12-05 00:27:35 +0100727 (
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
736test_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
744test_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 )
Jens Lehmann1414e572009-09-22 17:10:12 +0200750'
751
Jens Lehmann4d689322011-06-06 21:58:04 +0200752test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
Jens Lehmann8537f0e2011-06-06 21:57:01 +0200753 (
754 cd addtest &&
Jens Lehmann4d689322011-06-06 21:58:04 +0200755 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"
Jens Lehmann8537f0e2011-06-06 21:57:01 +0200759 )
760'
761
Thomas Rastea640cc2011-01-10 11:37:26 +0100762test_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 &&
Jon Seymour712693e2012-06-03 19:46:47 +1000776 cp .git/config pristine-.git-config &&
777 cp .gitmodules pristine-.gitmodules
Thomas Rastea640cc2011-01-10 11:37:26 +0100778 )
779'
780
Jon Seymour712693e2012-06-03 19:46:47 +1000781test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
Thomas Rastea640cc2011-01-10 11:37:26 +0100782 (
783 cd reltest &&
784 cp pristine-.git-config .git/config &&
Jon Seymour712693e2012-06-03 19:46:47 +1000785 cp pristine-.gitmodules .gitmodules &&
Thomas Rastea640cc2011-01-10 11:37:26 +0100786 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
Jon Seymour712693e2012-06-03 19:46:47 +1000792test_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
Johannes Sixtc517e732012-06-14 14:10:27 +0200803# 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
808test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
Jon Seymour712693e2012-06-03 19:46:47 +1000809 (
810 cd reltest &&
811 cp pristine-.git-config .git/config &&
812 cp pristine-.gitmodules .gitmodules &&
Johannes Sixtc517e732012-06-14 14:10:27 +0200813 git config remote.origin.url "//somewhere else/repo" &&
Jon Seymour712693e2012-06-03 19:46:47 +1000814 git submodule init &&
Johannes Sixtc517e732012-06-14 14:10:27 +0200815 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
Jon Seymour712693e2012-06-03 19:46:47 +1000816 )
817'
818
819test_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
830test_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
841test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
Thomas Rastea640cc2011-01-10 11:37:26 +0100842 (
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
Jon Seymour712693e2012-06-03 19:46:47 +1000851test_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
Jon Seymour758615e2012-06-06 21:57:30 +1000862test_expect_success '../subrepo works with relative local path - foo' '
Jon Seymour49301c62012-06-03 19:46:48 +1000863 (
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
Jon Seymour712693e2012-06-03 19:46:47 +1000874test_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
Jon Seymour758615e2012-06-06 21:57:30 +1000885test_expect_success '../subrepo works with relative local path - ./foo' '
Jon Seymour49301c62012-06-03 19:46:48 +1000886 (
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
Jon Seymour758615e2012-06-06 21:57:30 +1000896test_expect_success '../subrepo works with relative local path - ./foo/bar' '
Jon Seymour49301c62012-06-03 19:46:48 +1000897 (
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
Jon Seymour712693e2012-06-03 19:46:47 +1000907test_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
918test_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
929test_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 &&
Kyle Meyere1381112019-04-09 19:07:35 -0400935 (cd a/b/c && git init && test_commit msg) &&
Jon Seymour712693e2012-06-03 19:46:47 +1000936 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
Jens Lehmannd75219b2012-03-04 22:15:08 +0100943test_expect_success 'moving the superproject does not break submodules' '
944 (
945 cd addtest &&
946 git submodule status >expect
Jeff King99094a72015-03-20 06:07:15 -0400947 ) &&
Jens Lehmannd75219b2012-03-04 22:15:08 +0100948 mv addtest addtest2 &&
949 (
950 cd addtest2 &&
951 git submodule status >actual &&
952 test_cmp expect actual
953 )
954'
955
René Scharfe74b6bda2018-03-28 23:14:08 +0200956test_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
Jens Lehmann73b08982012-09-30 01:05:58 +0200971test_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 &&
Junio C Hamanoca8d1482013-06-09 11:29:20 -0700985 test_must_be_empty actual &&
Jens Lehmann73b08982012-09-30 01:05:58 +0200986 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 &&
Jens Lehmann95c16412013-08-06 21:15:25 +0200997 test_must_fail git config -f .gitmodules submodule.repo.path &&
Jens Lehmann73b08982012-09-30 01:05:58 +0200998 git config -f .gitmodules submodule.repo_new.path >actual &&
Andrei Rybak64d10222020-03-22 22:14:22 +0100999 test_cmp expect actual &&
Jens Lehmann73b08982012-09-30 01:05:58 +02001000 echo "$submodurl/repo" >expect &&
Jens Lehmann95c16412013-08-06 21:15:25 +02001001 test_must_fail git config -f .gitmodules submodule.repo.url &&
Jens Lehmann73b08982012-09-30 01:05:58 +02001002 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
Stefan Bellerf8eaa0b2016-03-31 17:17:28 -07001014test_expect_success 'recursive relative submodules stay relative' '
Stefan Beller3fea1212016-03-31 14:04:36 -07001015 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
1053'
1054
Jens Lehmann4b7c2862012-09-30 23:01:29 +02001055test_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 &&
Jens Lehmann95c16412013-08-06 21:15:25 +02001062 test_must_fail git config -f .gitmodules submodule.repo_new.path &&
1063 test_must_fail git config -f .gitmodules submodule.repo_new.url &&
Jens Lehmann4b7c2862012-09-30 23:01:29 +02001064 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 &&
Andrei Rybak64d10222020-03-22 22:14:22 +01001071 test_cmp expect actual &&
Jens Lehmann4b7c2862012-09-30 23:01:29 +02001072 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
Jens Lehmanncf419822013-03-04 22:20:24 +01001081test_expect_success 'set up a second submodule' '
1082 git submodule add ./init2 example2 &&
1083 git commit -m "submodule example2 added"
1084'
1085
Stefan Beller84ba9592016-03-22 16:42:14 -07001086test_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 &&
Stefan Beller14544dd2016-05-02 15:24:02 -07001094 git commit -m "repo should not be empty" &&
Stefan Bellerf6a52792016-05-05 12:52:32 -07001095 git submodule deinit . &&
1096 git submodule deinit --all
Stefan Beller84ba9592016-03-22 16:42:14 -07001097 )
1098'
1099
Jens Lehmanncf419822013-03-04 22:20:24 +01001100test_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
Stefan Beller8eda5ef2018-12-14 15:59:45 -08001110test_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
John Keeping091a6eb2013-06-16 15:18:18 +01001115test_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 ) &&
Junio C Hamano67892752023-10-31 14:23:30 +09001123 test_grep "\\.\\./init" output &&
John Keeping091a6eb2013-06-16 15:18:18 +01001124 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
Jens Lehmanncf419822013-03-04 22:20:24 +01001130test_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 &&
Jens Lehmann7b294bf2013-04-01 21:02:00 +02001135 git submodule deinit . >actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001136 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1137 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
Junio C Hamano67892752023-10-31 14:23:30 +09001138 test_grep "Cleared directory .init" actual &&
1139 test_grep "Cleared directory .example2" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001140 rmdir init example2
1141'
1142
Stefan Bellerf6a52792016-05-05 12:52:32 -07001143test_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\.")" &&
Junio C Hamano67892752023-10-31 14:23:30 +09001151 test_grep "Cleared directory .init" actual &&
1152 test_grep "Cleared directory .example2" actual &&
Stefan Bellerf6a52792016-05-05 12:52:32 -07001153 rmdir init example2
1154'
1155
Jens Lehmanncf419822013-03-04 22:20:24 +01001156test_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 &&
Jens Lehmann7b294bf2013-04-01 21:02:00 +02001159 git submodule deinit init example2 >actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001160 test -z "$(git config --get-regexp "submodule\.example\.")" &&
1161 test -z "$(git config --get-regexp "submodule\.example2\.")" &&
Junio C Hamano67892752023-10-31 14:23:30 +09001162 test_grep ! "Cleared directory .init" actual &&
1163 test_grep "Cleared directory .example2" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001164 rmdir init
1165'
1166
1167test_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 &&
Jens Lehmann7b294bf2013-04-01 21:02:00 +02001173 git submodule deinit -f init >actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001174 test -z "$(git config --get-regexp "submodule\.example\.")" &&
Junio C Hamano67892752023-10-31 14:23:30 +09001175 test_grep "Cleared directory .init" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001176 rmdir init
1177'
1178
1179test_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 &&
Jens Lehmann7b294bf2013-04-01 21:02:00 +02001185 git submodule deinit -f init >actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001186 test -z "$(git config --get-regexp "submodule\.example\.")" &&
Junio C Hamano67892752023-10-31 14:23:30 +09001187 test_grep "Cleared directory .init" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001188 rmdir init
1189'
1190
1191test_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 &&
Jens Lehmann7b294bf2013-04-01 21:02:00 +02001200 git submodule deinit -f init >actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001201 test -z "$(git config --get-regexp "submodule\.example\.")" &&
Junio C Hamano67892752023-10-31 14:23:30 +09001202 test_grep "Cleared directory .init" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001203 rmdir init
1204'
1205
1206test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
1207 git submodule update --init &&
1208 git submodule deinit init >actual &&
Junio C Hamano67892752023-10-31 14:23:30 +09001209 test_grep "Submodule .example. (.*) unregistered for path .init" actual &&
1210 test_grep "Cleared directory .init" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001211 git submodule deinit init >actual &&
Junio C Hamano67892752023-10-31 14:23:30 +09001212 test_grep ! "Submodule .example. (.*) unregistered for path .init" actual &&
1213 test_grep "Cleared directory .init" actual &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001214 git submodule deinit . >actual &&
Junio C Hamano67892752023-10-31 14:23:30 +09001215 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 &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001218 git submodule deinit . >actual &&
Junio C Hamano67892752023-10-31 14:23:30 +09001219 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 &&
Stefan Bellerf6a52792016-05-05 12:52:32 -07001222 git submodule deinit --all >actual &&
Junio C Hamano67892752023-10-31 14:23:30 +09001223 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 &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001226 rmdir init example2
1227'
1228
Mugdha Pattnaik0adc8ba2021-11-19 10:56:27 +00001229test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' '
Jens Lehmanncf419822013-03-04 22:20:24 +01001230 git submodule update --init &&
1231 (
1232 cd init &&
1233 rm .git &&
Mugdha Pattnaik0adc8ba2021-11-19 10:56:27 +00001234 mv ../.git/modules/example .git &&
Jens Lehmanncf419822013-03-04 22:20:24 +01001235 GIT_WORK_TREE=. git config --unset core.worktree
1236 ) &&
Mugdha Pattnaik0adc8ba2021-11-19 10:56:27 +00001237 git submodule deinit init &&
1238 test_path_is_missing init/.git &&
1239 test -z "$(git config --get-regexp "submodule\.example\.")"
Jens Lehmanncf419822013-03-04 22:20:24 +01001240'
1241
Torsten Bögershausenbed94702013-06-20 16:58:48 +02001242test_expect_success 'submodule with UTF-8 name' '
1243 svname=$(printf "\303\245 \303\244\303\266") &&
1244 mkdir "$svname" &&
Fredrik Gustafsson74671242013-06-14 02:26:02 +02001245 (
Torsten Bögershausenbed94702013-06-20 16:58:48 +02001246 cd "$svname" &&
Fredrik Gustafsson74671242013-06-14 02:26:02 +02001247 git init &&
Torsten Bögershausenbed94702013-06-20 16:58:48 +02001248 >sub &&
1249 git add sub &&
Fredrik Gustafsson74671242013-06-14 02:26:02 +02001250 git commit -m "init sub"
Torsten Bögershausenbed94702013-06-20 16:58:48 +02001251 ) &&
Torsten Bögershausenbed94702013-06-20 16:58:48 +02001252 git submodule add ./"$svname" &&
1253 git submodule >&2 &&
1254 test -n "$(git submodule | grep "$svname")"
Fredrik Gustafsson74671242013-06-14 02:26:02 +02001255'
Junio C Hamano2bb7afa2013-07-15 10:28:48 -07001256
Fredrik Gustafsson275cd182013-07-02 23:42:56 +02001257test_expect_success 'submodule add clone shallow submodule' '
1258 mkdir super &&
Jeff King99094a72015-03-20 06:07:15 -04001259 pwd=$(pwd) &&
Fredrik Gustafsson275cd182013-07-02 23:42:56 +02001260 (
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
Brandon Williams3e7eaed2017-03-17 15:38:02 -07001271test_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
1283cat >expect <<-EOF
1284-sub0
1285 sub1 (test2)
1286 sub2 (test2)
1287 sub3 (test2)
1288EOF
1289
1290test_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" &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001295 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Brandon Williams3e7eaed2017-03-17 15:38:02 -07001296 test_cmp expect actual
1297'
1298
1299test_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 &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001306 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Brandon Williams3e7eaed2017-03-17 15:38:02 -07001307 test_cmp expect actual
1308'
1309
1310test_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 &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001325 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Brandon Williams3e7eaed2017-03-17 15:38:02 -07001326 test_cmp expect actual
1327'
Fredrik Gustafsson275cd182013-07-02 23:42:56 +02001328
Stefan Bellere0a862f2018-10-16 10:27:03 -07001329test_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
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001342 cut -d" " -f3- actual_raw >actual &&
Stefan Bellere0a862f2018-10-16 10:27:03 -07001343 cat >expect <<-\EOF &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001344 sub0 (test2)
1345 sub1 (test2)
1346 sub2 (test2)
1347 sub3 (test2)
Stefan Bellere0a862f2018-10-16 10:27:03 -07001348 EOF
1349 test_cmp expect actual
1350 )
1351'
1352
Taylor Blaufbc806a2023-05-24 15:51:43 -04001353test_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
Brandon Williamsbb62e0a2017-03-17 15:38:03 -07001369test_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 &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001379 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -07001380 test_cmp expected actual
Brandon Williamsbb62e0a2017-03-17 15:38:03 -07001381'
1382
1383test_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 &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001396 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Brandon Williamsbb62e0a2017-03-17 15:38:03 -07001397 test_cmp expect actual
1398'
1399
1400test_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
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001424 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Brandon Williamsbb62e0a2017-03-17 15:38:03 -07001425 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 &&
brian m. carlsonc0b65ea2020-07-29 23:14:03 +00001433 git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual &&
Brandon Williamsbb62e0a2017-03-17 15:38:03 -07001434 test_cmp expect2 actual
1435'
1436
Brandon Williams1f8d7112017-03-17 15:38:04 -07001437test_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
Brandon Williams03c004c2017-08-03 15:25:44 -07001448test_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
Johannes Schindelin4412a042024-03-29 13:15:32 +01001454test_expect_success '`submodule init` and `init.templateDir`' '
1455 mkdir -p tmpl/hooks &&
1456 write_script tmpl/hooks/post-checkout <<-EOF &&
1457 echo HOOK-RUN >&2
1458 echo I was here >hook.run
1459 exit 1
1460 EOF
1461
1462 test_config init.templateDir "$(pwd)/tmpl" &&
1463 test_when_finished \
1464 "git config --global --unset init.templateDir || true" &&
1465 (
1466 sane_unset GIT_TEMPLATE_DIR &&
1467 NO_SET_GIT_TEMPLATE_DIR=t &&
1468 export NO_SET_GIT_TEMPLATE_DIR &&
1469
1470 git config --global init.templateDir "$(pwd)/tmpl" &&
1471 test_must_fail git submodule \
1472 add "$submodurl" sub-global 2>err &&
1473 git config --global --unset init.templateDir &&
Johannes Schindelin8e97ec32024-04-10 22:04:48 +02001474 test_grep HOOK-RUN err &&
Johannes Schindelin4412a042024-03-29 13:15:32 +01001475 test_path_is_file sub-global/hook.run &&
1476
1477 git config init.templateDir "$(pwd)/tmpl" &&
1478 git submodule add "$submodurl" sub-local 2>err &&
1479 git config --unset init.templateDir &&
Johannes Schindelin8e97ec32024-04-10 22:04:48 +02001480 test_grep ! HOOK-RUN err &&
Johannes Schindelin4412a042024-03-29 13:15:32 +01001481 test_path_is_missing sub-local/hook.run
1482 )
1483'
1484
Lars Hjemli88961ef2007-06-02 03:27:42 +02001485test_done