blob: ea92ef52a5eb9c593039614a6e42fa308a68b852 [file] [log] [blame]
David Aguilar52e83702008-10-02 02:11:55 -07001#!/bin/sh
2#
3# Copyright (c) 2008 David Aguilar
4#
5
6test_description='git submodule sync
7
8These tests exercise the "git submodule sync" subcommand.
9'
10
Johannes Schindelin01dc8132020-11-18 23:44:39 +000011GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +000012export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13
David Aguilar52e83702008-10-02 02:11:55 -070014. ./test-lib.sh
15
16test_expect_success setup '
Taylor Blau0d3beb72022-07-29 15:21:40 -040017 git config --global protocol.file.allow always &&
18
John Keeping031129c2013-06-16 15:18:14 +010019 echo file >file &&
David Aguilar52e83702008-10-02 02:11:55 -070020 git add file &&
21 test_tick &&
Jens Lehmann0eb032d2010-08-18 23:20:33 +020022 git commit -m upstream &&
David Aguilar52e83702008-10-02 02:11:55 -070023 git clone . super &&
24 git clone super submodule &&
John Keeping031129c2013-06-16 15:18:14 +010025 (
26 cd submodule &&
27 git submodule add ../submodule sub-submodule &&
28 test_tick &&
29 git commit -m "sub-submodule"
Phil Hord44fa0ef2012-10-26 15:44:43 -040030 ) &&
John Keeping031129c2013-06-16 15:18:14 +010031 (
32 cd super &&
33 git submodule add ../submodule submodule &&
34 test_tick &&
35 git commit -m "submodule"
David Aguilar52e83702008-10-02 02:11:55 -070036 ) &&
37 git clone super super-clone &&
John Keeping031129c2013-06-16 15:18:14 +010038 (
39 cd super-clone &&
40 git submodule update --init --recursive
41 ) &&
Andreas Köhler33f072f2010-10-08 03:07:48 +020042 git clone super empty-clone &&
John Keeping031129c2013-06-16 15:18:14 +010043 (
44 cd empty-clone &&
45 git submodule init
46 ) &&
Jon Seymour49301c62012-06-03 19:46:48 +100047 git clone super top-only-clone &&
48 git clone super relative-clone &&
John Keeping031129c2013-06-16 15:18:14 +010049 (
50 cd relative-clone &&
51 git submodule update --init --recursive
52 ) &&
Phil Hord44fa0ef2012-10-26 15:44:43 -040053 git clone super recursive-clone &&
John Keeping031129c2013-06-16 15:18:14 +010054 (
55 cd recursive-clone &&
56 git submodule update --init --recursive
57 )
David Aguilar52e83702008-10-02 02:11:55 -070058'
59
60test_expect_success 'change submodule' '
John Keeping031129c2013-06-16 15:18:14 +010061 (
62 cd submodule &&
63 echo second line >>file &&
64 test_tick &&
65 git commit -a -m "change submodule"
David Aguilar52e83702008-10-02 02:11:55 -070066 )
67'
68
John Keeping091a6eb2013-06-16 15:18:18 +010069reset_submodule_urls () {
John Keeping091a6eb2013-06-16 15:18:18 +010070 (
Junio C Hamanoe256eec2016-06-01 13:56:08 -070071 root=$(pwd) &&
John Keeping091a6eb2013-06-16 15:18:18 +010072 cd super-clone/submodule &&
73 git config remote.origin.url "$root/submodule"
74 ) &&
75 (
Junio C Hamanoe256eec2016-06-01 13:56:08 -070076 root=$(pwd) &&
John Keeping091a6eb2013-06-16 15:18:18 +010077 cd super-clone/submodule/sub-submodule &&
78 git config remote.origin.url "$root/submodule"
79 )
80}
81
David Aguilar52e83702008-10-02 02:11:55 -070082test_expect_success 'change submodule url' '
John Keeping031129c2013-06-16 15:18:14 +010083 (
84 cd super &&
85 cd submodule &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +000086 git checkout main &&
John Keeping031129c2013-06-16 15:18:14 +010087 git pull
David Aguilar52e83702008-10-02 02:11:55 -070088 ) &&
89 mv submodule moved-submodule &&
John Keeping031129c2013-06-16 15:18:14 +010090 (
91 cd moved-submodule &&
92 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
93 test_tick &&
94 git commit -a -m moved-sub-submodule
Phil Hord44fa0ef2012-10-26 15:44:43 -040095 ) &&
John Keeping031129c2013-06-16 15:18:14 +010096 (
97 cd super &&
98 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
99 test_tick &&
100 git commit -a -m moved-submodule
David Aguilar52e83702008-10-02 02:11:55 -0700101 )
102'
103
104test_expect_success '"git submodule sync" should update submodule URLs' '
John Keeping031129c2013-06-16 15:18:14 +0100105 (
106 cd super-clone &&
107 git pull --no-recurse-submodules &&
108 git submodule sync
David Aguilar52e83702008-10-02 02:11:55 -0700109 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100110 test -d "$(
111 cd super-clone/submodule &&
112 git config remote.origin.url
Fredrik Gustafssonabc06822011-08-15 23:17:46 +0200113 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100114 test ! -d "$(
115 cd super-clone/submodule/sub-submodule &&
116 git config remote.origin.url
Phil Hord44fa0ef2012-10-26 15:44:43 -0400117 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100118 (
119 cd super-clone/submodule &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000120 git checkout main &&
John Keeping031129c2013-06-16 15:18:14 +0100121 git pull
David Aguilar0b9dca42010-08-18 08:58:33 -0700122 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100123 (
124 cd super-clone &&
125 test -d "$(git config submodule.submodule.url)"
David Aguilar52e83702008-10-02 02:11:55 -0700126 )
127'
128
Phil Hord44fa0ef2012-10-26 15:44:43 -0400129test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
John Keeping031129c2013-06-16 15:18:14 +0100130 (
131 cd super-clone &&
132 (
133 cd submodule &&
134 git pull --no-recurse-submodules
135 ) &&
136 git submodule sync --recursive
Phil Hord44fa0ef2012-10-26 15:44:43 -0400137 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100138 test -d "$(
139 cd super-clone/submodule &&
140 git config remote.origin.url
Phil Hord44fa0ef2012-10-26 15:44:43 -0400141 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100142 test -d "$(
143 cd super-clone/submodule/sub-submodule &&
144 git config remote.origin.url
Phil Hord44fa0ef2012-10-26 15:44:43 -0400145 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100146 (
147 cd super-clone/submodule/sub-submodule &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000148 git checkout main &&
John Keeping031129c2013-06-16 15:18:14 +0100149 git pull
Phil Hord44fa0ef2012-10-26 15:44:43 -0400150 )
151'
152
John Keeping091a6eb2013-06-16 15:18:18 +0100153test_expect_success 'reset submodule URLs' '
154 reset_submodule_urls super-clone
155'
156
157test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
158 (
159 cd super-clone &&
160 git pull --no-recurse-submodules &&
161 mkdir -p sub &&
162 cd sub &&
163 git submodule sync >../../output
164 ) &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +0000165 test_i18ngrep "\\.\\./submodule" output &&
John Keeping091a6eb2013-06-16 15:18:18 +0100166 test -d "$(
167 cd super-clone/submodule &&
168 git config remote.origin.url
169 )" &&
170 test ! -d "$(
171 cd super-clone/submodule/sub-submodule &&
172 git config remote.origin.url
173 )" &&
174 (
175 cd super-clone/submodule &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000176 git checkout main &&
John Keeping091a6eb2013-06-16 15:18:18 +0100177 git pull
178 ) &&
179 (
180 cd super-clone &&
181 test -d "$(git config submodule.submodule.url)"
182 )
183'
184
185test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
186 (
187 cd super-clone &&
188 (
189 cd submodule &&
190 git pull --no-recurse-submodules
191 ) &&
192 mkdir -p sub &&
193 cd sub &&
194 git submodule sync --recursive >../../output
195 ) &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +0000196 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
John Keeping091a6eb2013-06-16 15:18:18 +0100197 test -d "$(
198 cd super-clone/submodule &&
199 git config remote.origin.url
200 )" &&
201 test -d "$(
202 cd super-clone/submodule/sub-submodule &&
203 git config remote.origin.url
204 )" &&
205 (
206 cd super-clone/submodule/sub-submodule &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000207 git checkout main &&
John Keeping091a6eb2013-06-16 15:18:18 +0100208 git pull
209 )
210'
211
Junio C Hamanoccee6082011-06-25 22:41:25 +0200212test_expect_success '"git submodule sync" should update known submodule URLs' '
John Keeping031129c2013-06-16 15:18:14 +0100213 (
214 cd empty-clone &&
215 git pull &&
216 git submodule sync &&
217 test -d "$(git config submodule.submodule.url)"
Andreas Köhler33f072f2010-10-08 03:07:48 +0200218 )
219'
220
Junio C Hamanoccee6082011-06-25 22:41:25 +0200221test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
John Keeping031129c2013-06-16 15:18:14 +0100222 (
223 cd top-only-clone &&
224 git pull &&
225 git submodule sync &&
226 test -z "$(git config submodule.submodule.url)" &&
227 git submodule sync submodule &&
228 test -z "$(git config submodule.submodule.url)"
Junio C Hamanoccee6082011-06-25 22:41:25 +0200229 )
230'
231
Jon Seymour758615e2012-06-06 21:57:30 +1000232test_expect_success '"git submodule sync" handles origin URL of the form foo' '
John Keeping031129c2013-06-16 15:18:14 +0100233 (
234 cd relative-clone &&
235 git remote set-url origin foo &&
236 git submodule sync &&
237 (
238 cd submodule &&
239 #actual fails with: "cannot strip off url foo
240 test "$(git config remote.origin.url)" = "../submodule"
241 )
Jon Seymour49301c62012-06-03 19:46:48 +1000242 )
243'
244
Jon Seymour967b2c62012-06-06 21:57:29 +1000245test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
John Keeping031129c2013-06-16 15:18:14 +0100246 (
247 cd relative-clone &&
248 git remote set-url origin foo/bar &&
249 git submodule sync &&
250 (
251 cd submodule &&
252 #actual foo/submodule
253 test "$(git config remote.origin.url)" = "../foo/submodule"
John Keepinga82af052013-06-16 15:18:15 +0100254 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100255 (
256 cd submodule/sub-submodule &&
257 test "$(git config remote.origin.url)" != "../../foo/submodule"
258 )
Phil Hord44fa0ef2012-10-26 15:44:43 -0400259 )
260'
261
262test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
John Keeping031129c2013-06-16 15:18:14 +0100263 (
264 cd recursive-clone &&
265 git remote set-url origin foo/bar &&
266 git submodule sync --recursive &&
267 (
268 cd submodule &&
269 #actual foo/submodule
270 test "$(git config remote.origin.url)" = "../foo/submodule"
John Keepinga82af052013-06-16 15:18:15 +0100271 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100272 (
273 cd submodule/sub-submodule &&
274 test "$(git config remote.origin.url)" = "../../foo/submodule"
275 )
Jon Seymour49301c62012-06-03 19:46:48 +1000276 )
277'
278
Jon Seymour758615e2012-06-06 21:57:30 +1000279test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
John Keeping031129c2013-06-16 15:18:14 +0100280 (
281 cd relative-clone &&
282 git remote set-url origin ./foo &&
283 git submodule sync &&
284 (
285 cd submodule &&
286 #actual ./submodule
287 test "$(git config remote.origin.url)" = "../submodule"
288 )
Jon Seymour49301c62012-06-03 19:46:48 +1000289 )
290'
291
Jon Seymour758615e2012-06-06 21:57:30 +1000292test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
John Keeping031129c2013-06-16 15:18:14 +0100293 (
294 cd relative-clone &&
295 git remote set-url origin ./foo/bar &&
296 git submodule sync &&
297 (
298 cd submodule &&
299 #actual ./foo/submodule
300 test "$(git config remote.origin.url)" = "../foo/submodule"
301 )
Jon Seymour49301c62012-06-03 19:46:48 +1000302 )
303'
304
Jon Seymour967b2c62012-06-06 21:57:29 +1000305test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
John Keeping031129c2013-06-16 15:18:14 +0100306 (
307 cd relative-clone &&
308 git remote set-url origin ../foo &&
309 git submodule sync &&
310 (
311 cd submodule &&
312 #actual ../submodule
313 test "$(git config remote.origin.url)" = "../../submodule"
314 )
Jon Seymour49301c62012-06-03 19:46:48 +1000315 )
316'
317
Jon Seymour967b2c62012-06-06 21:57:29 +1000318test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
John Keeping031129c2013-06-16 15:18:14 +0100319 (
320 cd relative-clone &&
321 git remote set-url origin ../foo/bar &&
322 git submodule sync &&
323 (
324 cd submodule &&
325 #actual ../foo/submodule
326 test "$(git config remote.origin.url)" = "../../foo/submodule"
327 )
Jon Seymour49301c62012-06-03 19:46:48 +1000328 )
329'
330
Jon Seymour967b2c62012-06-06 21:57:29 +1000331test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
John Keeping031129c2013-06-16 15:18:14 +0100332 (
333 cd relative-clone &&
334 git remote set-url origin ../foo/bar &&
335 mkdir -p a/b/c &&
336 (
337 cd a/b/c &&
338 git init &&
339 >.gitignore &&
340 git add .gitignore &&
341 test_tick &&
342 git commit -m "initial commit"
343 ) &&
344 git submodule add ../bar/a/b/c ./a/b/c &&
345 git submodule sync &&
346 (
347 cd a/b/c &&
348 #actual ../foo/bar/a/b/c
349 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
350 )
Jon Seymour49301c62012-06-03 19:46:48 +1000351 )
352'
353
354
David Aguilar52e83702008-10-02 02:11:55 -0700355test_done