]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7403-submodule-sync.sh
The fifteenth batch
[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
01dc8133 11GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
12export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13
b2e5d75d 14TEST_PASSES_SANITIZE_LEAK=true
52e8370b
DA
15. ./test-lib.sh
16
17test_expect_success setup '
0d3beb71
TB
18 git config --global protocol.file.allow always &&
19
031129cb 20 echo file >file &&
52e8370b
DA
21 git add file &&
22 test_tick &&
0eb032d8 23 git commit -m upstream &&
52e8370b
DA
24 git clone . super &&
25 git clone super submodule &&
031129cb
JK
26 (
27 cd submodule &&
28 git submodule add ../submodule sub-submodule &&
29 test_tick &&
30 git commit -m "sub-submodule"
44fa0ef5 31 ) &&
031129cb
JK
32 (
33 cd super &&
34 git submodule add ../submodule submodule &&
35 test_tick &&
36 git commit -m "submodule"
52e8370b
DA
37 ) &&
38 git clone super super-clone &&
031129cb
JK
39 (
40 cd super-clone &&
41 git submodule update --init --recursive
42 ) &&
33f072f8 43 git clone super empty-clone &&
031129cb
JK
44 (
45 cd empty-clone &&
46 git submodule init
47 ) &&
49301c64
JS
48 git clone super top-only-clone &&
49 git clone super relative-clone &&
031129cb
JK
50 (
51 cd relative-clone &&
52 git submodule update --init --recursive
53 ) &&
44fa0ef5 54 git clone super recursive-clone &&
031129cb
JK
55 (
56 cd recursive-clone &&
57 git submodule update --init --recursive
58 )
52e8370b
DA
59'
60
61test_expect_success 'change submodule' '
031129cb
JK
62 (
63 cd submodule &&
64 echo second line >>file &&
65 test_tick &&
66 git commit -a -m "change submodule"
52e8370b
DA
67 )
68'
69
091a6eb0 70reset_submodule_urls () {
091a6eb0 71 (
e256eec7 72 root=$(pwd) &&
091a6eb0
JK
73 cd super-clone/submodule &&
74 git config remote.origin.url "$root/submodule"
75 ) &&
76 (
e256eec7 77 root=$(pwd) &&
091a6eb0
JK
78 cd super-clone/submodule/sub-submodule &&
79 git config remote.origin.url "$root/submodule"
80 )
81}
82
52e8370b 83test_expect_success 'change submodule url' '
031129cb
JK
84 (
85 cd super &&
86 cd submodule &&
01dc8133 87 git checkout main &&
031129cb 88 git pull
52e8370b
DA
89 ) &&
90 mv submodule moved-submodule &&
031129cb
JK
91 (
92 cd moved-submodule &&
93 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
94 test_tick &&
95 git commit -a -m moved-sub-submodule
44fa0ef5 96 ) &&
031129cb
JK
97 (
98 cd super &&
99 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
100 test_tick &&
101 git commit -a -m moved-submodule
52e8370b
DA
102 )
103'
104
105test_expect_success '"git submodule sync" should update submodule URLs' '
031129cb
JK
106 (
107 cd super-clone &&
108 git pull --no-recurse-submodules &&
109 git submodule sync
52e8370b 110 ) &&
031129cb
JK
111 test -d "$(
112 cd super-clone/submodule &&
113 git config remote.origin.url
abc06822 114 )" &&
031129cb
JK
115 test ! -d "$(
116 cd super-clone/submodule/sub-submodule &&
117 git config remote.origin.url
44fa0ef5 118 )" &&
031129cb
JK
119 (
120 cd super-clone/submodule &&
01dc8133 121 git checkout main &&
031129cb 122 git pull
0b9dca43 123 ) &&
031129cb
JK
124 (
125 cd super-clone &&
126 test -d "$(git config submodule.submodule.url)"
52e8370b
DA
127 )
128'
129
44fa0ef5 130test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
031129cb
JK
131 (
132 cd super-clone &&
133 (
134 cd submodule &&
135 git pull --no-recurse-submodules
136 ) &&
137 git submodule sync --recursive
44fa0ef5 138 ) &&
031129cb
JK
139 test -d "$(
140 cd super-clone/submodule &&
141 git config remote.origin.url
44fa0ef5 142 )" &&
031129cb
JK
143 test -d "$(
144 cd super-clone/submodule/sub-submodule &&
145 git config remote.origin.url
44fa0ef5 146 )" &&
031129cb
JK
147 (
148 cd super-clone/submodule/sub-submodule &&
01dc8133 149 git checkout main &&
031129cb 150 git pull
44fa0ef5
PH
151 )
152'
153
091a6eb0
JK
154test_expect_success 'reset submodule URLs' '
155 reset_submodule_urls super-clone
156'
157
158test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
159 (
160 cd super-clone &&
161 git pull --no-recurse-submodules &&
162 mkdir -p sub &&
163 cd sub &&
164 git submodule sync >../../output
165 ) &&
6789275d 166 test_grep "\\.\\./submodule" output &&
091a6eb0
JK
167 test -d "$(
168 cd super-clone/submodule &&
169 git config remote.origin.url
170 )" &&
171 test ! -d "$(
172 cd super-clone/submodule/sub-submodule &&
173 git config remote.origin.url
174 )" &&
175 (
176 cd super-clone/submodule &&
01dc8133 177 git checkout main &&
091a6eb0
JK
178 git pull
179 ) &&
180 (
181 cd super-clone &&
182 test -d "$(git config submodule.submodule.url)"
183 )
184'
185
186test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
187 (
188 cd super-clone &&
189 (
190 cd submodule &&
191 git pull --no-recurse-submodules
192 ) &&
193 mkdir -p sub &&
194 cd sub &&
195 git submodule sync --recursive >../../output
196 ) &&
6789275d 197 test_grep "\\.\\./submodule/sub-submodule" output &&
091a6eb0
JK
198 test -d "$(
199 cd super-clone/submodule &&
200 git config remote.origin.url
201 )" &&
202 test -d "$(
203 cd super-clone/submodule/sub-submodule &&
204 git config remote.origin.url
205 )" &&
206 (
207 cd super-clone/submodule/sub-submodule &&
01dc8133 208 git checkout main &&
091a6eb0
JK
209 git pull
210 )
211'
212
ccee6086 213test_expect_success '"git submodule sync" should update known submodule URLs' '
031129cb
JK
214 (
215 cd empty-clone &&
216 git pull &&
217 git submodule sync &&
218 test -d "$(git config submodule.submodule.url)"
33f072f8
AK
219 )
220'
221
ccee6086 222test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
031129cb
JK
223 (
224 cd top-only-clone &&
225 git pull &&
226 git submodule sync &&
227 test -z "$(git config submodule.submodule.url)" &&
228 git submodule sync submodule &&
229 test -z "$(git config submodule.submodule.url)"
ccee6086
JH
230 )
231'
232
758615e2 233test_expect_success '"git submodule sync" handles origin URL of the form foo' '
031129cb
JK
234 (
235 cd relative-clone &&
236 git remote set-url origin foo &&
237 git submodule sync &&
238 (
239 cd submodule &&
240 #actual fails with: "cannot strip off url foo
241 test "$(git config remote.origin.url)" = "../submodule"
242 )
49301c64
JS
243 )
244'
245
967b2c66 246test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
031129cb
JK
247 (
248 cd relative-clone &&
249 git remote set-url origin foo/bar &&
250 git submodule sync &&
251 (
252 cd submodule &&
253 #actual foo/submodule
254 test "$(git config remote.origin.url)" = "../foo/submodule"
a82af054 255 ) &&
031129cb
JK
256 (
257 cd submodule/sub-submodule &&
258 test "$(git config remote.origin.url)" != "../../foo/submodule"
259 )
44fa0ef5
PH
260 )
261'
262
263test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
031129cb
JK
264 (
265 cd recursive-clone &&
266 git remote set-url origin foo/bar &&
267 git submodule sync --recursive &&
268 (
269 cd submodule &&
270 #actual foo/submodule
271 test "$(git config remote.origin.url)" = "../foo/submodule"
a82af054 272 ) &&
031129cb
JK
273 (
274 cd submodule/sub-submodule &&
275 test "$(git config remote.origin.url)" = "../../foo/submodule"
276 )
49301c64
JS
277 )
278'
279
758615e2 280test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
031129cb
JK
281 (
282 cd relative-clone &&
283 git remote set-url origin ./foo &&
284 git submodule sync &&
285 (
286 cd submodule &&
287 #actual ./submodule
288 test "$(git config remote.origin.url)" = "../submodule"
289 )
49301c64
JS
290 )
291'
292
758615e2 293test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
031129cb
JK
294 (
295 cd relative-clone &&
296 git remote set-url origin ./foo/bar &&
297 git submodule sync &&
298 (
299 cd submodule &&
300 #actual ./foo/submodule
301 test "$(git config remote.origin.url)" = "../foo/submodule"
302 )
49301c64
JS
303 )
304'
305
967b2c66 306test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
031129cb
JK
307 (
308 cd relative-clone &&
309 git remote set-url origin ../foo &&
310 git submodule sync &&
311 (
312 cd submodule &&
313 #actual ../submodule
314 test "$(git config remote.origin.url)" = "../../submodule"
315 )
49301c64
JS
316 )
317'
318
967b2c66 319test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
031129cb
JK
320 (
321 cd relative-clone &&
322 git remote set-url origin ../foo/bar &&
323 git submodule sync &&
324 (
325 cd submodule &&
326 #actual ../foo/submodule
327 test "$(git config remote.origin.url)" = "../../foo/submodule"
328 )
49301c64
JS
329 )
330'
331
967b2c66 332test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
031129cb
JK
333 (
334 cd relative-clone &&
335 git remote set-url origin ../foo/bar &&
336 mkdir -p a/b/c &&
337 (
338 cd a/b/c &&
339 git init &&
340 >.gitignore &&
341 git add .gitignore &&
342 test_tick &&
343 git commit -m "initial commit"
344 ) &&
345 git submodule add ../bar/a/b/c ./a/b/c &&
346 git submodule sync &&
347 (
348 cd a/b/c &&
349 #actual ../foo/bar/a/b/c
350 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
351 )
49301c64
JS
352 )
353'
354
355
52e8370b 356test_done