blob: c73bec9551eb27dab25aad69c83ae7ce9f9b11a8 [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
12. ./test-lib.sh
13
Jonathan Niederfe454b12010-04-10 00:38:37 -050014test_expect_success 'setup - initial commit' '
15 >t &&
Nanako Shiraishi47a528a2008-09-03 17:59:33 +090016 git add t &&
17 git commit -m "initial commit" &&
Jonathan Niederfe454b12010-04-10 00:38:37 -050018 git branch initial
19'
20
21test_expect_success 'setup - repository in init subdirectory' '
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -080022 mkdir init &&
Jonathan Niederfe454b12010-04-10 00:38:37 -050023 (
24 cd init &&
25 git init &&
26 echo a >a &&
27 git add a &&
28 git commit -m "submodule commit 1" &&
29 git tag -a -m "rev-1" rev-1
30 )
Jonathan Niederfe454b12010-04-10 00:38:37 -050031'
32
33test_expect_success 'setup - commit with gitlink' '
Lars Hjemli88961ef2007-06-02 03:27:42 +020034 echo a >a &&
35 echo z >z &&
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -080036 git add a init z &&
Jonathan Niederfe454b12010-04-10 00:38:37 -050037 git commit -m "super commit 1"
38'
39
40test_expect_success 'setup - hide init subdirectory' '
41 mv init .subrepo
42'
43
Jonathan Niedera76c9442010-04-10 00:39:04 -050044test_expect_success 'setup - repository to add submodules to' '
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +000045 git init addtest &&
46 git init addtest-ignore
Michael J Gruberac8463d2009-03-03 16:08:20 +010047'
48
Jonathan Niedera76c9442010-04-10 00:39:04 -050049# The 'submodule add' tests need some repository to add as a submodule.
Jeff Kingdd008b32011-07-30 09:05:54 -060050# The trash directory is a good one as any. We need to canonicalize
51# the name, though, as some tests compare it to the absolute path git
52# generates, which will expand symbolic links.
53submodurl=$(pwd -P)
Jonathan Niedera76c9442010-04-10 00:39:04 -050054
55listbranches() {
56 git for-each-ref --format='%(refname)' 'refs/heads/*'
57}
58
59inspect() {
60 dir=$1 &&
61 dotdot="${2:-..}" &&
62
63 (
64 cd "$dir" &&
65 listbranches >"$dotdot/heads" &&
66 { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -050067 git rev-parse HEAD >"$dotdot/head-sha1" &&
Jonathan Niedera76c9442010-04-10 00:39:04 -050068 git update-index --refresh &&
69 git diff-files --exit-code &&
70 git clean -n -d -x >"$dotdot/untracked"
71 )
72}
73
Michael J Gruberac8463d2009-03-03 16:08:20 +010074test_expect_success 'submodule add' '
Jonathan Niedera76c9442010-04-10 00:39:04 -050075 echo "refs/heads/master" >expect &&
76 >empty &&
77
Michael J Gruberac8463d2009-03-03 16:08:20 +010078 (
79 cd addtest &&
Jens Lehmann7e604072011-07-26 23:39:03 +020080 git submodule add -q "$submodurl" submod >actual &&
81 test ! -s actual &&
Jens Lehmannea115a02012-03-04 22:14:30 +010082 echo "gitdir: ../.git/modules/submod" >expect &&
83 test_cmp expect submod/.git &&
Jens Lehmannd75219b2012-03-04 22:15:08 +010084 (
85 cd submod &&
86 git config core.worktree >actual &&
87 echo "../../../submod" >expect &&
88 test_cmp expect actual &&
89 rm -f actual expect
90 ) &&
Michael J Gruberac8463d2009-03-03 16:08:20 +010091 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -050092 ) &&
93
94 rm -f heads head untracked &&
95 inspect addtest/submod ../.. &&
96 test_cmp expect heads &&
97 test_cmp expect head &&
98 test_cmp empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +010099'
100
Jens Lehmannd27b8762010-07-17 17:11:43 +0200101test_expect_success 'submodule add to .gitignored path fails' '
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000102 (
103 cd addtest-ignore &&
Jens Lehmannd27b8762010-07-17 17:11:43 +0200104 cat <<-\EOF >expect &&
105 The following path is ignored by one of your .gitignore files:
106 submod
107 Use -f if you really want to add it.
108 EOF
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000109 # Does not use test_commit due to the ignore
110 echo "*" > .gitignore &&
111 git add --force .gitignore &&
112 git commit -m"Ignore everything" &&
Jens Lehmannd27b8762010-07-17 17:11:43 +0200113 ! git submodule add "$submodurl" submod >actual 2>&1 &&
Ævar Arnfjörð Bjarmason3a4c3ed2011-05-21 18:44:07 +0000114 test_i18ncmp expect actual
Jens Lehmannd27b8762010-07-17 17:11:43 +0200115 )
116'
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000117
Jens Lehmannd27b8762010-07-17 17:11:43 +0200118test_expect_success 'submodule add to .gitignored path with --force' '
119 (
120 cd addtest-ignore &&
121 git submodule add --force "$submodurl" submod
122 )
Ævar Arnfjörð Bjarmason31991b02010-07-05 17:33:03 +0000123'
124
Ben Jacksonea10b602009-04-18 20:42:07 -0700125test_expect_success 'submodule add --branch' '
Jonathan Niedera76c9442010-04-10 00:39:04 -0500126 echo "refs/heads/initial" >expect-head &&
127 cat <<-\EOF >expect-heads &&
128 refs/heads/initial
129 refs/heads/master
130 EOF
131 >empty &&
132
Ben Jacksonea10b602009-04-18 20:42:07 -0700133 (
134 cd addtest &&
135 git submodule add -b initial "$submodurl" submod-branch &&
Jonathan Niedera76c9442010-04-10 00:39:04 -0500136 git submodule init
137 ) &&
138
139 rm -f heads head untracked &&
140 inspect addtest/submod-branch ../.. &&
141 test_cmp expect-heads heads &&
142 test_cmp expect-head head &&
143 test_cmp empty untracked
Ben Jacksonea10b602009-04-18 20:42:07 -0700144'
145
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100146test_expect_success 'submodule add with ./ in path' '
Jonathan Niedera76c9442010-04-10 00:39:04 -0500147 echo "refs/heads/master" >expect &&
148 >empty &&
149
Michael J Gruberac8463d2009-03-03 16:08:20 +0100150 (
151 cd addtest &&
152 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
153 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500154 ) &&
155
156 rm -f heads head untracked &&
157 inspect addtest/dotsubmod/frotz ../../.. &&
158 test_cmp expect heads &&
159 test_cmp expect head &&
160 test_cmp empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100161'
162
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100163test_expect_success 'submodule add with // in path' '
Jonathan Niedera76c9442010-04-10 00:39:04 -0500164 echo "refs/heads/master" >expect &&
165 >empty &&
166
Michael J Gruberac8463d2009-03-03 16:08:20 +0100167 (
168 cd addtest &&
169 git submodule add "$submodurl" slashslashsubmod///frotz// &&
170 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500171 ) &&
172
173 rm -f heads head untracked &&
174 inspect addtest/slashslashsubmod/frotz ../../.. &&
175 test_cmp expect heads &&
176 test_cmp expect head &&
177 test_cmp empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100178'
179
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100180test_expect_success 'submodule add with /.. in path' '
Jonathan Niedera76c9442010-04-10 00:39:04 -0500181 echo "refs/heads/master" >expect &&
182 >empty &&
183
Michael J Gruberac8463d2009-03-03 16:08:20 +0100184 (
185 cd addtest &&
186 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
187 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500188 ) &&
189
190 rm -f heads head untracked &&
191 inspect addtest/realsubmod ../.. &&
192 test_cmp expect heads &&
193 test_cmp expect head &&
194 test_cmp empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100195'
196
Michael J Gruberdb75ada2009-03-03 16:08:21 +0100197test_expect_success 'submodule add with ./, /.. and // in path' '
Jonathan Niedera76c9442010-04-10 00:39:04 -0500198 echo "refs/heads/master" >expect &&
199 >empty &&
200
Michael J Gruberac8463d2009-03-03 16:08:20 +0100201 (
202 cd addtest &&
203 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
204 git submodule init
Jonathan Niedera76c9442010-04-10 00:39:04 -0500205 ) &&
206
207 rm -f heads head untracked &&
208 inspect addtest/realsubmod2 ../.. &&
209 test_cmp expect heads &&
210 test_cmp expect head &&
211 test_cmp empty untracked
Michael J Gruberac8463d2009-03-03 16:08:20 +0100212'
213
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500214test_expect_success 'setup - add an example entry to .gitmodules' '
215 GIT_CONFIG=.gitmodules \
216 git config submodule.example.url git://example.com/init.git
217'
218
Lars Hjemli941987a2007-06-11 21:12:24 +0200219test_expect_success 'status should fail for unmapped paths' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500220 test_must_fail git submodule status
221'
222
223test_expect_success 'setup - map path in .gitmodules' '
224 cat <<\EOF >expect &&
225[submodule "example"]
226 url = git://example.com/init.git
227 path = init
228EOF
229
230 GIT_CONFIG=.gitmodules git config submodule.example.path init &&
231
232 test_cmp expect .gitmodules
Lars Hjemli88961ef2007-06-02 03:27:42 +0200233'
234
235test_expect_success 'status should only print one line' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500236 git submodule status >lines &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200237 test_line_count = 1 lines
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500238'
239
240test_expect_success 'setup - fetch commit name from submodule' '
241 rev1=$(cd .subrepo && git rev-parse HEAD) &&
242 printf "rev1: %s\n" "$rev1" &&
243 test -n "$rev1"
Lars Hjemli88961ef2007-06-02 03:27:42 +0200244'
245
246test_expect_success 'status should initially be "missing"' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500247 git submodule status >lines &&
248 grep "^-$rev1" lines
Lars Hjemli88961ef2007-06-02 03:27:42 +0200249'
250
Lars Hjemli211b7f12007-06-06 11:13:02 +0200251test_expect_success 'init should register submodule url in .git/config' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500252 echo git://example.com/init.git >expect &&
253
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900254 git submodule init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500255 git config submodule.example.url >url &&
256 git config submodule.example.url ./.subrepo &&
257
258 test_cmp expect url
Lars Hjemli211b7f12007-06-06 11:13:02 +0200259'
260
261test_expect_success 'update should fail when path is used by a file' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500262 echo hello >expect &&
263
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800264 echo "hello" >init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500265 test_must_fail git submodule update &&
266
267 test_cmp expect init
Lars Hjemli88961ef2007-06-02 03:27:42 +0200268'
269
Lars Hjemli211b7f12007-06-06 11:13:02 +0200270test_expect_success 'update should fail when path is used by a nonempty directory' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500271 echo hello >expect &&
272
273 rm -fr init &&
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800274 mkdir init &&
275 echo "hello" >init/a &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500276
277 test_must_fail git submodule update &&
278
279 test_cmp expect init/a
Lars Hjemli88961ef2007-06-02 03:27:42 +0200280'
281
Lars Hjemli211b7f12007-06-06 11:13:02 +0200282test_expect_success 'update should work when path is an empty dir' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500283 rm -fr init &&
284 rm -f head-sha1 &&
285 echo "$rev1" >expect &&
286
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800287 mkdir init &&
Jens Lehmann7e604072011-07-26 23:39:03 +0200288 git submodule update -q >update.out &&
289 test ! -s update.out &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500290
291 inspect init &&
292 test_cmp expect head-sha1
Lars Hjemli88961ef2007-06-02 03:27:42 +0200293'
294
Lars Hjemli211b7f12007-06-06 11:13:02 +0200295test_expect_success 'status should be "up-to-date" after update' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500296 git submodule status >list &&
297 grep "^ $rev1" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200298'
299
300test_expect_success 'status should be "modified" after submodule commit' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500301 (
302 cd init &&
303 echo b >b &&
304 git add b &&
305 git commit -m "submodule commit 2"
306 ) &&
307
308 rev2=$(cd init && git rev-parse HEAD) &&
309 test -n "$rev2" &&
310 git submodule status >list &&
311
312 grep "^+$rev2" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200313'
314
315test_expect_success 'the --cached sha1 should be rev1' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500316 git submodule --cached status >list &&
317 grep "^+$rev1" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200318'
319
Sven Verdoolaege57011152007-09-08 12:30:22 +0200320test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500321 git diff >diff &&
322 grep "^+Subproject commit $rev2" diff
Sven Verdoolaege57011152007-09-08 12:30:22 +0200323'
324
Lars Hjemli88961ef2007-06-02 03:27:42 +0200325test_expect_success 'update should checkout rev1' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500326 rm -f head-sha1 &&
327 echo "$rev1" >expect &&
328
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900329 git submodule update init &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500330 inspect init &&
331
332 test_cmp expect head-sha1
Lars Hjemli88961ef2007-06-02 03:27:42 +0200333'
334
335test_expect_success 'status should be "up-to-date" after update' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500336 git submodule status >list &&
337 grep "^ $rev1" list
Lars Hjemli88961ef2007-06-02 03:27:42 +0200338'
339
Sven Verdoolaege0cf73752007-07-17 20:28:28 +0200340test_expect_success 'checkout superproject with subproject already present' '
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900341 git checkout initial &&
342 git checkout master
Sven Verdoolaege0cf73752007-07-17 20:28:28 +0200343'
344
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200345test_expect_success 'apply submodule diff' '
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500346 >empty &&
347
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200348 git branch second &&
349 (
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800350 cd init &&
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200351 echo s >s &&
352 git add s &&
353 git commit -m "change subproject"
354 ) &&
Junio C Hamanoa2d93ae2008-01-15 03:13:55 -0800355 git update-index --add init &&
Nanako Shiraishi47a528a2008-09-03 17:59:33 +0900356 git commit -m "change init" &&
357 git format-patch -1 --stdout >P.diff &&
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200358 git checkout second &&
359 git apply --index P.diff &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500360
361 git diff --cached master >staged &&
362 test_cmp empty staged
Sven Verdoolaegee06c5a62007-08-15 19:22:09 +0200363'
364
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100365test_expect_success 'update --init' '
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100366 mv init init2 &&
367 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500368 git config --remove-section submodule.example &&
369 test_must_fail git config submodule.example.url &&
370
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100371 git submodule update init > update.out &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500372 cat update.out &&
Ævar Arnfjörð Bjarmason1c2ef662011-05-21 18:44:08 +0000373 test_i18ngrep "not initialized" update.out &&
Fredrik Gustafssonabc06822011-08-15 23:17:46 +0200374 test_must_fail git rev-parse --resolve-git-dir init/.git &&
Jonathan Niederce8b54d2010-04-10 00:39:41 -0500375
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100376 git submodule update --init init &&
Fredrik Gustafssonabc06822011-08-15 23:17:46 +0200377 git rev-parse --resolve-git-dir init/.git
Johannes Schindelinbe4d2c82008-05-16 11:23:03 +0100378'
379
Johannes Schindelin2ce53f92009-01-02 19:08:40 +0100380test_expect_success 'do not add files from a submodule' '
381
382 git reset --hard &&
383 test_must_fail git add init/a
384
385'
386
387test_expect_success 'gracefully add submodule with a trailing slash' '
388
389 git reset --hard &&
390 git commit -m "commit subproject" init &&
391 (cd init &&
392 echo b > a) &&
393 git add init/ &&
394 git diff --exit-code --cached init &&
395 commit=$(cd init &&
396 git commit -m update a >/dev/null &&
397 git rev-parse HEAD) &&
398 git add init/ &&
399 test_must_fail git diff --exit-code --cached init &&
400 test $commit = $(git ls-files --stage |
401 sed -n "s/^160000 \([^ ]*\).*/\1/p")
402
403'
404
Johannes Schindelinf3670a52009-02-07 14:43:03 +0100405test_expect_success 'ls-files gracefully handles trailing slash' '
406
407 test "init" = "$(git ls-files init/)"
408
409'
410
Peter Collingbournec5e558a2010-01-11 02:59:54 +0000411test_expect_success 'moving to a commit without submodule does not leave empty dir' '
412 rm -rf init &&
413 mkdir init &&
414 git reset --hard &&
415 git checkout initial &&
416 test ! -d init &&
417 git checkout second
418'
419
Johannes Schindelin496917b2009-02-07 14:43:15 +0100420test_expect_success 'submodule <invalid-path> warns' '
421
422 git submodule no-such-submodule 2> output.err &&
423 grep "^error: .*no-such-submodule" output.err
424
425'
426
Jens Lehmann1414e572009-09-22 17:10:12 +0200427test_expect_success 'add submodules without specifying an explicit path' '
428 mkdir repo &&
Jonathan Nieder18a82692010-09-06 20:42:54 -0500429 (
430 cd repo &&
431 git init &&
432 echo r >r &&
433 git add r &&
434 git commit -m "repo commit 1"
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +0200435 ) &&
Jens Lehmann1414e572009-09-22 17:10:12 +0200436 git clone --bare repo/ bare.git &&
Jens Lehmann69e72362010-12-05 00:27:35 +0100437 (
438 cd addtest &&
439 git submodule add "$submodurl/repo" &&
440 git config -f .gitmodules submodule.repo.path repo &&
441 git submodule add "$submodurl/bare.git" &&
442 git config -f .gitmodules submodule.bare.path bare
443 )
444'
445
446test_expect_success 'add should fail when path is used by a file' '
447 (
448 cd addtest &&
449 touch file &&
450 test_must_fail git submodule add "$submodurl/repo" file
451 )
452'
453
454test_expect_success 'add should fail when path is used by an existing directory' '
455 (
456 cd addtest &&
457 mkdir empty-dir &&
458 test_must_fail git submodule add "$submodurl/repo" empty-dir
459 )
Jens Lehmann1414e572009-09-22 17:10:12 +0200460'
461
Jens Lehmann4d689322011-06-06 21:58:04 +0200462test_expect_success 'use superproject as upstream when path is relative and no url is set there' '
Jens Lehmann8537f0e2011-06-06 21:57:01 +0200463 (
464 cd addtest &&
Jens Lehmann4d689322011-06-06 21:58:04 +0200465 git submodule add ../repo relative &&
466 test "$(git config -f .gitmodules submodule.relative.url)" = ../repo &&
467 git submodule sync relative &&
468 test "$(git config submodule.relative.url)" = "$submodurl/repo"
Jens Lehmann8537f0e2011-06-06 21:57:01 +0200469 )
470'
471
Thomas Rastea640cc2011-01-10 11:37:26 +0100472test_expect_success 'set up for relative path tests' '
473 mkdir reltest &&
474 (
475 cd reltest &&
476 git init &&
477 mkdir sub &&
478 (
479 cd sub &&
480 git init &&
481 test_commit foo
482 ) &&
483 git add sub &&
484 git config -f .gitmodules submodule.sub.path sub &&
485 git config -f .gitmodules submodule.sub.url ../subrepo &&
Jon Seymour712693e2012-06-03 19:46:47 +1000486 cp .git/config pristine-.git-config &&
487 cp .gitmodules pristine-.gitmodules
Thomas Rastea640cc2011-01-10 11:37:26 +0100488 )
489'
490
Jon Seymour712693e2012-06-03 19:46:47 +1000491test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
Thomas Rastea640cc2011-01-10 11:37:26 +0100492 (
493 cd reltest &&
494 cp pristine-.git-config .git/config &&
Jon Seymour712693e2012-06-03 19:46:47 +1000495 cp pristine-.gitmodules .gitmodules &&
Thomas Rastea640cc2011-01-10 11:37:26 +0100496 git config remote.origin.url ssh://hostname/repo &&
497 git submodule init &&
498 test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
499 )
500'
501
Jon Seymour712693e2012-06-03 19:46:47 +1000502test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
503 (
504 cd reltest &&
505 cp pristine-.git-config .git/config &&
506 cp pristine-.gitmodules .gitmodules &&
507 git config remote.origin.url ssh://hostname:22/repo &&
508 git submodule init &&
509 test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
510 )
511'
512
Johannes Sixtc517e732012-06-14 14:10:27 +0200513# About the choice of the path in the next test:
514# - double-slash side-steps path mangling issues on Windows
515# - it is still an absolute local path
516# - there cannot be a server with a blank in its name just in case the
517# path is used erroneously to access a //server/share style path
518test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
Jon Seymour712693e2012-06-03 19:46:47 +1000519 (
520 cd reltest &&
521 cp pristine-.git-config .git/config &&
522 cp pristine-.gitmodules .gitmodules &&
Johannes Sixtc517e732012-06-14 14:10:27 +0200523 git config remote.origin.url "//somewhere else/repo" &&
Jon Seymour712693e2012-06-03 19:46:47 +1000524 git submodule init &&
Johannes Sixtc517e732012-06-14 14:10:27 +0200525 test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
Jon Seymour712693e2012-06-03 19:46:47 +1000526 )
527'
528
529test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
530 (
531 cd reltest &&
532 cp pristine-.git-config .git/config &&
533 cp pristine-.gitmodules .gitmodules &&
534 git config remote.origin.url file:///tmp/repo &&
535 git submodule init &&
536 test "$(git config submodule.sub.url)" = file:///tmp/subrepo
537 )
538'
539
540test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
541 (
542 cd reltest &&
543 cp pristine-.git-config .git/config &&
544 cp pristine-.gitmodules .gitmodules &&
545 git config remote.origin.url helper:://hostname/repo &&
546 git submodule init &&
547 test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
548 )
549'
550
551test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
Thomas Rastea640cc2011-01-10 11:37:26 +0100552 (
553 cd reltest &&
554 cp pristine-.git-config .git/config &&
555 git config remote.origin.url user@host:repo &&
556 git submodule init &&
557 test "$(git config submodule.sub.url)" = user@host:subrepo
558 )
559'
560
Jon Seymour712693e2012-06-03 19:46:47 +1000561test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
562 (
563 cd reltest &&
564 cp pristine-.git-config .git/config &&
565 cp pristine-.gitmodules .gitmodules &&
566 git config remote.origin.url user@host:path/to/repo &&
567 git submodule init &&
568 test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
569 )
570'
571
Jon Seymour758615e2012-06-06 21:57:30 +1000572test_expect_success '../subrepo works with relative local path - foo' '
Jon Seymour49301c62012-06-03 19:46:48 +1000573 (
574 cd reltest &&
575 cp pristine-.git-config .git/config &&
576 cp pristine-.gitmodules .gitmodules &&
577 git config remote.origin.url foo &&
578 # actual: fails with an error
579 git submodule init &&
580 test "$(git config submodule.sub.url)" = subrepo
581 )
582'
583
Jon Seymour712693e2012-06-03 19:46:47 +1000584test_expect_success '../subrepo works with relative local path - foo/bar' '
585 (
586 cd reltest &&
587 cp pristine-.git-config .git/config &&
588 cp pristine-.gitmodules .gitmodules &&
589 git config remote.origin.url foo/bar &&
590 git submodule init &&
591 test "$(git config submodule.sub.url)" = foo/subrepo
592 )
593'
594
Jon Seymour758615e2012-06-06 21:57:30 +1000595test_expect_success '../subrepo works with relative local path - ./foo' '
Jon Seymour49301c62012-06-03 19:46:48 +1000596 (
597 cd reltest &&
598 cp pristine-.git-config .git/config &&
599 cp pristine-.gitmodules .gitmodules &&
600 git config remote.origin.url ./foo &&
601 git submodule init &&
602 test "$(git config submodule.sub.url)" = subrepo
603 )
604'
605
Jon Seymour758615e2012-06-06 21:57:30 +1000606test_expect_success '../subrepo works with relative local path - ./foo/bar' '
Jon Seymour49301c62012-06-03 19:46:48 +1000607 (
608 cd reltest &&
609 cp pristine-.git-config .git/config &&
610 cp pristine-.gitmodules .gitmodules &&
611 git config remote.origin.url ./foo/bar &&
612 git submodule init &&
613 test "$(git config submodule.sub.url)" = foo/subrepo
614 )
615'
616
Jon Seymour712693e2012-06-03 19:46:47 +1000617test_expect_success '../subrepo works with relative local path - ../foo' '
618 (
619 cd reltest &&
620 cp pristine-.git-config .git/config &&
621 cp pristine-.gitmodules .gitmodules &&
622 git config remote.origin.url ../foo &&
623 git submodule init &&
624 test "$(git config submodule.sub.url)" = ../subrepo
625 )
626'
627
628test_expect_success '../subrepo works with relative local path - ../foo/bar' '
629 (
630 cd reltest &&
631 cp pristine-.git-config .git/config &&
632 cp pristine-.gitmodules .gitmodules &&
633 git config remote.origin.url ../foo/bar &&
634 git submodule init &&
635 test "$(git config submodule.sub.url)" = ../foo/subrepo
636 )
637'
638
639test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
640 (
641 cd reltest &&
642 cp pristine-.git-config .git/config &&
643 cp pristine-.gitmodules .gitmodules &&
644 mkdir -p a/b/c &&
645 (cd a/b/c; git init) &&
646 git config remote.origin.url ../foo/bar.git &&
647 git submodule add ../bar/a/b/c ./a/b/c &&
648 git submodule init &&
649 test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
650 )
651'
652
Jens Lehmannd75219b2012-03-04 22:15:08 +0100653test_expect_success 'moving the superproject does not break submodules' '
654 (
655 cd addtest &&
656 git submodule status >expect
657 )
658 mv addtest addtest2 &&
659 (
660 cd addtest2 &&
661 git submodule status >actual &&
662 test_cmp expect actual
663 )
664'
665
Lars Hjemli88961ef2007-06-02 03:27:42 +0200666test_done