]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7403-submodule-sync.sh
path.c: don't call the match function without value in trie_find()
[thirdparty/git.git] / t / t7403-submodule-sync.sh
CommitLineData
52e8370b
DA
1#!/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 '
031129cb 14 echo file >file &&
52e8370b
DA
15 git add file &&
16 test_tick &&
0eb032d8 17 git commit -m upstream &&
52e8370b
DA
18 git clone . super &&
19 git clone super submodule &&
031129cb
JK
20 (
21 cd submodule &&
22 git submodule add ../submodule sub-submodule &&
23 test_tick &&
24 git commit -m "sub-submodule"
44fa0ef5 25 ) &&
031129cb
JK
26 (
27 cd super &&
28 git submodule add ../submodule submodule &&
29 test_tick &&
30 git commit -m "submodule"
52e8370b
DA
31 ) &&
32 git clone super super-clone &&
031129cb
JK
33 (
34 cd super-clone &&
35 git submodule update --init --recursive
36 ) &&
33f072f8 37 git clone super empty-clone &&
031129cb
JK
38 (
39 cd empty-clone &&
40 git submodule init
41 ) &&
49301c64
JS
42 git clone super top-only-clone &&
43 git clone super relative-clone &&
031129cb
JK
44 (
45 cd relative-clone &&
46 git submodule update --init --recursive
47 ) &&
44fa0ef5 48 git clone super recursive-clone &&
031129cb
JK
49 (
50 cd recursive-clone &&
51 git submodule update --init --recursive
52 )
52e8370b
DA
53'
54
55test_expect_success 'change submodule' '
031129cb
JK
56 (
57 cd submodule &&
58 echo second line >>file &&
59 test_tick &&
60 git commit -a -m "change submodule"
52e8370b
DA
61 )
62'
63
091a6eb0 64reset_submodule_urls () {
091a6eb0 65 (
e256eec7 66 root=$(pwd) &&
091a6eb0
JK
67 cd super-clone/submodule &&
68 git config remote.origin.url "$root/submodule"
69 ) &&
70 (
e256eec7 71 root=$(pwd) &&
091a6eb0
JK
72 cd super-clone/submodule/sub-submodule &&
73 git config remote.origin.url "$root/submodule"
74 )
75}
76
52e8370b 77test_expect_success 'change submodule url' '
031129cb
JK
78 (
79 cd super &&
80 cd submodule &&
81 git checkout master &&
82 git pull
52e8370b
DA
83 ) &&
84 mv submodule moved-submodule &&
031129cb
JK
85 (
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
44fa0ef5 90 ) &&
031129cb
JK
91 (
92 cd super &&
93 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
94 test_tick &&
95 git commit -a -m moved-submodule
52e8370b
DA
96 )
97'
98
99test_expect_success '"git submodule sync" should update submodule URLs' '
031129cb
JK
100 (
101 cd super-clone &&
102 git pull --no-recurse-submodules &&
103 git submodule sync
52e8370b 104 ) &&
031129cb
JK
105 test -d "$(
106 cd super-clone/submodule &&
107 git config remote.origin.url
abc06822 108 )" &&
031129cb
JK
109 test ! -d "$(
110 cd super-clone/submodule/sub-submodule &&
111 git config remote.origin.url
44fa0ef5 112 )" &&
031129cb
JK
113 (
114 cd super-clone/submodule &&
115 git checkout master &&
116 git pull
0b9dca43 117 ) &&
031129cb
JK
118 (
119 cd super-clone &&
120 test -d "$(git config submodule.submodule.url)"
52e8370b
DA
121 )
122'
123
44fa0ef5 124test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
031129cb
JK
125 (
126 cd super-clone &&
127 (
128 cd submodule &&
129 git pull --no-recurse-submodules
130 ) &&
131 git submodule sync --recursive
44fa0ef5 132 ) &&
031129cb
JK
133 test -d "$(
134 cd super-clone/submodule &&
135 git config remote.origin.url
44fa0ef5 136 )" &&
031129cb
JK
137 test -d "$(
138 cd super-clone/submodule/sub-submodule &&
139 git config remote.origin.url
44fa0ef5 140 )" &&
031129cb
JK
141 (
142 cd super-clone/submodule/sub-submodule &&
143 git checkout master &&
144 git pull
44fa0ef5
PH
145 )
146'
147
091a6eb0
JK
148test_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 ) &&
1edbaac3 160 test_i18ngrep "\\.\\./submodule" output &&
091a6eb0
JK
161 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 ) &&
1edbaac3 191 test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
091a6eb0
JK
192 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
ccee6086 207test_expect_success '"git submodule sync" should update known submodule URLs' '
031129cb
JK
208 (
209 cd empty-clone &&
210 git pull &&
211 git submodule sync &&
212 test -d "$(git config submodule.submodule.url)"
33f072f8
AK
213 )
214'
215
ccee6086 216test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
031129cb
JK
217 (
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)"
ccee6086
JH
224 )
225'
226
758615e2 227test_expect_success '"git submodule sync" handles origin URL of the form foo' '
031129cb
JK
228 (
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 )
49301c64
JS
237 )
238'
239
967b2c66 240test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
031129cb
JK
241 (
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"
a82af054 249 ) &&
031129cb
JK
250 (
251 cd submodule/sub-submodule &&
252 test "$(git config remote.origin.url)" != "../../foo/submodule"
253 )
44fa0ef5
PH
254 )
255'
256
257test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
031129cb
JK
258 (
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"
a82af054 266 ) &&
031129cb
JK
267 (
268 cd submodule/sub-submodule &&
269 test "$(git config remote.origin.url)" = "../../foo/submodule"
270 )
49301c64
JS
271 )
272'
273
758615e2 274test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
031129cb
JK
275 (
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 )
49301c64
JS
284 )
285'
286
758615e2 287test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
031129cb
JK
288 (
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 )
49301c64
JS
297 )
298'
299
967b2c66 300test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
031129cb
JK
301 (
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 )
49301c64
JS
310 )
311'
312
967b2c66 313test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
031129cb
JK
314 (
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 )
49301c64
JS
323 )
324'
325
967b2c66 326test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
031129cb
JK
327 (
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 )
49301c64
JS
346 )
347'
348
349
52e8370b 350test_done