blob: 0726799e74e7a587e920c35f356b3364737b70d2 [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
11. ./test-lib.sh
12
13test_expect_success setup '
John Keeping031129c2013-06-16 15:18:14 +010014 echo file >file &&
David Aguilar52e83702008-10-02 02:11:55 -070015 git add file &&
16 test_tick &&
Jens Lehmann0eb032d2010-08-18 23:20:33 +020017 git commit -m upstream &&
David Aguilar52e83702008-10-02 02:11:55 -070018 git clone . super &&
19 git clone super submodule &&
John Keeping031129c2013-06-16 15:18:14 +010020 (
21 cd submodule &&
22 git submodule add ../submodule sub-submodule &&
23 test_tick &&
24 git commit -m "sub-submodule"
Phil Hord44fa0ef2012-10-26 15:44:43 -040025 ) &&
John Keeping031129c2013-06-16 15:18:14 +010026 (
27 cd super &&
28 git submodule add ../submodule submodule &&
29 test_tick &&
30 git commit -m "submodule"
David Aguilar52e83702008-10-02 02:11:55 -070031 ) &&
32 git clone super super-clone &&
John Keeping031129c2013-06-16 15:18:14 +010033 (
34 cd super-clone &&
35 git submodule update --init --recursive
36 ) &&
Andreas Köhler33f072f2010-10-08 03:07:48 +020037 git clone super empty-clone &&
John Keeping031129c2013-06-16 15:18:14 +010038 (
39 cd empty-clone &&
40 git submodule init
41 ) &&
Jon Seymour49301c62012-06-03 19:46:48 +100042 git clone super top-only-clone &&
43 git clone super relative-clone &&
John Keeping031129c2013-06-16 15:18:14 +010044 (
45 cd relative-clone &&
46 git submodule update --init --recursive
47 ) &&
Phil Hord44fa0ef2012-10-26 15:44:43 -040048 git clone super recursive-clone &&
John Keeping031129c2013-06-16 15:18:14 +010049 (
50 cd recursive-clone &&
51 git submodule update --init --recursive
52 )
David Aguilar52e83702008-10-02 02:11:55 -070053'
54
55test_expect_success 'change submodule' '
John Keeping031129c2013-06-16 15:18:14 +010056 (
57 cd submodule &&
58 echo second line >>file &&
59 test_tick &&
60 git commit -a -m "change submodule"
David Aguilar52e83702008-10-02 02:11:55 -070061 )
62'
63
John Keeping091a6eb2013-06-16 15:18:18 +010064reset_submodule_urls () {
John Keeping091a6eb2013-06-16 15:18:18 +010065 (
Junio C Hamanoe256eec2016-06-01 13:56:08 -070066 root=$(pwd) &&
John Keeping091a6eb2013-06-16 15:18:18 +010067 cd super-clone/submodule &&
68 git config remote.origin.url "$root/submodule"
69 ) &&
70 (
Junio C Hamanoe256eec2016-06-01 13:56:08 -070071 root=$(pwd) &&
John Keeping091a6eb2013-06-16 15:18:18 +010072 cd super-clone/submodule/sub-submodule &&
73 git config remote.origin.url "$root/submodule"
74 )
75}
76
David Aguilar52e83702008-10-02 02:11:55 -070077test_expect_success 'change submodule url' '
John Keeping031129c2013-06-16 15:18:14 +010078 (
79 cd super &&
80 cd submodule &&
81 git checkout master &&
82 git pull
David Aguilar52e83702008-10-02 02:11:55 -070083 ) &&
84 mv submodule moved-submodule &&
John Keeping031129c2013-06-16 15:18:14 +010085 (
86 cd moved-submodule &&
87 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
88 test_tick &&
89 git commit -a -m moved-sub-submodule
Phil Hord44fa0ef2012-10-26 15:44:43 -040090 ) &&
John Keeping031129c2013-06-16 15:18:14 +010091 (
92 cd super &&
93 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
94 test_tick &&
95 git commit -a -m moved-submodule
David Aguilar52e83702008-10-02 02:11:55 -070096 )
97'
98
99test_expect_success '"git submodule sync" should update submodule URLs' '
John Keeping031129c2013-06-16 15:18:14 +0100100 (
101 cd super-clone &&
102 git pull --no-recurse-submodules &&
103 git submodule sync
David Aguilar52e83702008-10-02 02:11:55 -0700104 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100105 test -d "$(
106 cd super-clone/submodule &&
107 git config remote.origin.url
Fredrik Gustafssonabc06822011-08-15 23:17:46 +0200108 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100109 test ! -d "$(
110 cd super-clone/submodule/sub-submodule &&
111 git config remote.origin.url
Phil Hord44fa0ef2012-10-26 15:44:43 -0400112 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100113 (
114 cd super-clone/submodule &&
115 git checkout master &&
116 git pull
David Aguilar0b9dca42010-08-18 08:58:33 -0700117 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100118 (
119 cd super-clone &&
120 test -d "$(git config submodule.submodule.url)"
David Aguilar52e83702008-10-02 02:11:55 -0700121 )
122'
123
Phil Hord44fa0ef2012-10-26 15:44:43 -0400124test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
John Keeping031129c2013-06-16 15:18:14 +0100125 (
126 cd super-clone &&
127 (
128 cd submodule &&
129 git pull --no-recurse-submodules
130 ) &&
131 git submodule sync --recursive
Phil Hord44fa0ef2012-10-26 15:44:43 -0400132 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100133 test -d "$(
134 cd super-clone/submodule &&
135 git config remote.origin.url
Phil Hord44fa0ef2012-10-26 15:44:43 -0400136 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100137 test -d "$(
138 cd super-clone/submodule/sub-submodule &&
139 git config remote.origin.url
Phil Hord44fa0ef2012-10-26 15:44:43 -0400140 )" &&
John Keeping031129c2013-06-16 15:18:14 +0100141 (
142 cd super-clone/submodule/sub-submodule &&
143 git checkout master &&
144 git pull
Phil Hord44fa0ef2012-10-26 15:44:43 -0400145 )
146'
147
John Keeping091a6eb2013-06-16 15:18:18 +0100148test_expect_success 'reset submodule URLs' '
149 reset_submodule_urls super-clone
150'
151
152test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
153 (
154 cd super-clone &&
155 git pull --no-recurse-submodules &&
156 mkdir -p sub &&
157 cd sub &&
158 git submodule sync >../../output
159 ) &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +0000160 test_i18ngrep "\\.\\./submodule" output &&
John Keeping091a6eb2013-06-16 15:18:18 +0100161 test -d "$(
162 cd super-clone/submodule &&
163 git config remote.origin.url
164 )" &&
165 test ! -d "$(
166 cd super-clone/submodule/sub-submodule &&
167 git config remote.origin.url
168 )" &&
169 (
170 cd super-clone/submodule &&
171 git checkout master &&
172 git pull
173 ) &&
174 (
175 cd super-clone &&
176 test -d "$(git config submodule.submodule.url)"
177 )
178'
179
180test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
181 (
182 cd super-clone &&
183 (
184 cd submodule &&
185 git pull --no-recurse-submodules
186 ) &&
187 mkdir -p sub &&
188 cd sub &&
189 git submodule sync --recursive >../../output
190 ) &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +0000191 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
John Keeping091a6eb2013-06-16 15:18:18 +0100192 test -d "$(
193 cd super-clone/submodule &&
194 git config remote.origin.url
195 )" &&
196 test -d "$(
197 cd super-clone/submodule/sub-submodule &&
198 git config remote.origin.url
199 )" &&
200 (
201 cd super-clone/submodule/sub-submodule &&
202 git checkout master &&
203 git pull
204 )
205'
206
Junio C Hamanoccee6082011-06-25 22:41:25 +0200207test_expect_success '"git submodule sync" should update known submodule URLs' '
John Keeping031129c2013-06-16 15:18:14 +0100208 (
209 cd empty-clone &&
210 git pull &&
211 git submodule sync &&
212 test -d "$(git config submodule.submodule.url)"
Andreas Köhler33f072f2010-10-08 03:07:48 +0200213 )
214'
215
Junio C Hamanoccee6082011-06-25 22:41:25 +0200216test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
John Keeping031129c2013-06-16 15:18:14 +0100217 (
218 cd top-only-clone &&
219 git pull &&
220 git submodule sync &&
221 test -z "$(git config submodule.submodule.url)" &&
222 git submodule sync submodule &&
223 test -z "$(git config submodule.submodule.url)"
Junio C Hamanoccee6082011-06-25 22:41:25 +0200224 )
225'
226
Jon Seymour758615e2012-06-06 21:57:30 +1000227test_expect_success '"git submodule sync" handles origin URL of the form foo' '
John Keeping031129c2013-06-16 15:18:14 +0100228 (
229 cd relative-clone &&
230 git remote set-url origin foo &&
231 git submodule sync &&
232 (
233 cd submodule &&
234 #actual fails with: "cannot strip off url foo
235 test "$(git config remote.origin.url)" = "../submodule"
236 )
Jon Seymour49301c62012-06-03 19:46:48 +1000237 )
238'
239
Jon Seymour967b2c62012-06-06 21:57:29 +1000240test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
John Keeping031129c2013-06-16 15:18:14 +0100241 (
242 cd relative-clone &&
243 git remote set-url origin foo/bar &&
244 git submodule sync &&
245 (
246 cd submodule &&
247 #actual foo/submodule
248 test "$(git config remote.origin.url)" = "../foo/submodule"
John Keepinga82af052013-06-16 15:18:15 +0100249 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100250 (
251 cd submodule/sub-submodule &&
252 test "$(git config remote.origin.url)" != "../../foo/submodule"
253 )
Phil Hord44fa0ef2012-10-26 15:44:43 -0400254 )
255'
256
257test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
John Keeping031129c2013-06-16 15:18:14 +0100258 (
259 cd recursive-clone &&
260 git remote set-url origin foo/bar &&
261 git submodule sync --recursive &&
262 (
263 cd submodule &&
264 #actual foo/submodule
265 test "$(git config remote.origin.url)" = "../foo/submodule"
John Keepinga82af052013-06-16 15:18:15 +0100266 ) &&
John Keeping031129c2013-06-16 15:18:14 +0100267 (
268 cd submodule/sub-submodule &&
269 test "$(git config remote.origin.url)" = "../../foo/submodule"
270 )
Jon Seymour49301c62012-06-03 19:46:48 +1000271 )
272'
273
Jon Seymour758615e2012-06-06 21:57:30 +1000274test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
John Keeping031129c2013-06-16 15:18:14 +0100275 (
276 cd relative-clone &&
277 git remote set-url origin ./foo &&
278 git submodule sync &&
279 (
280 cd submodule &&
281 #actual ./submodule
282 test "$(git config remote.origin.url)" = "../submodule"
283 )
Jon Seymour49301c62012-06-03 19:46:48 +1000284 )
285'
286
Jon Seymour758615e2012-06-06 21:57:30 +1000287test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
John Keeping031129c2013-06-16 15:18:14 +0100288 (
289 cd relative-clone &&
290 git remote set-url origin ./foo/bar &&
291 git submodule sync &&
292 (
293 cd submodule &&
294 #actual ./foo/submodule
295 test "$(git config remote.origin.url)" = "../foo/submodule"
296 )
Jon Seymour49301c62012-06-03 19:46:48 +1000297 )
298'
299
Jon Seymour967b2c62012-06-06 21:57:29 +1000300test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
John Keeping031129c2013-06-16 15:18:14 +0100301 (
302 cd relative-clone &&
303 git remote set-url origin ../foo &&
304 git submodule sync &&
305 (
306 cd submodule &&
307 #actual ../submodule
308 test "$(git config remote.origin.url)" = "../../submodule"
309 )
Jon Seymour49301c62012-06-03 19:46:48 +1000310 )
311'
312
Jon Seymour967b2c62012-06-06 21:57:29 +1000313test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
John Keeping031129c2013-06-16 15:18:14 +0100314 (
315 cd relative-clone &&
316 git remote set-url origin ../foo/bar &&
317 git submodule sync &&
318 (
319 cd submodule &&
320 #actual ../foo/submodule
321 test "$(git config remote.origin.url)" = "../../foo/submodule"
322 )
Jon Seymour49301c62012-06-03 19:46:48 +1000323 )
324'
325
Jon Seymour967b2c62012-06-06 21:57:29 +1000326test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
John Keeping031129c2013-06-16 15:18:14 +0100327 (
328 cd relative-clone &&
329 git remote set-url origin ../foo/bar &&
330 mkdir -p a/b/c &&
331 (
332 cd a/b/c &&
333 git init &&
334 >.gitignore &&
335 git add .gitignore &&
336 test_tick &&
337 git commit -m "initial commit"
338 ) &&
339 git submodule add ../bar/a/b/c ./a/b/c &&
340 git submodule sync &&
341 (
342 cd a/b/c &&
343 #actual ../foo/bar/a/b/c
344 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
345 )
Jon Seymour49301c62012-06-03 19:46:48 +1000346 )
347'
348
349
David Aguilar52e83702008-10-02 02:11:55 -0700350test_done