]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7403-submodule-sync.sh
The third batch
[thirdparty/git.git] / t / t7403-submodule-sync.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 David Aguilar
4 #
5
6 test_description='git submodule sync
7
8 These tests exercise the "git submodule sync" subcommand.
9 '
10
11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13
14 TEST_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
16
17 test_expect_success setup '
18 git config --global protocol.file.allow always &&
19
20 echo file >file &&
21 git add file &&
22 test_tick &&
23 git commit -m upstream &&
24 git clone . super &&
25 git clone super submodule &&
26 (
27 cd submodule &&
28 git submodule add ../submodule sub-submodule &&
29 test_tick &&
30 git commit -m "sub-submodule"
31 ) &&
32 (
33 cd super &&
34 git submodule add ../submodule submodule &&
35 test_tick &&
36 git commit -m "submodule"
37 ) &&
38 git clone super super-clone &&
39 (
40 cd super-clone &&
41 git submodule update --init --recursive
42 ) &&
43 git clone super empty-clone &&
44 (
45 cd empty-clone &&
46 git submodule init
47 ) &&
48 git clone super top-only-clone &&
49 git clone super relative-clone &&
50 (
51 cd relative-clone &&
52 git submodule update --init --recursive
53 ) &&
54 git clone super recursive-clone &&
55 (
56 cd recursive-clone &&
57 git submodule update --init --recursive
58 )
59 '
60
61 test_expect_success 'change submodule' '
62 (
63 cd submodule &&
64 echo second line >>file &&
65 test_tick &&
66 git commit -a -m "change submodule"
67 )
68 '
69
70 reset_submodule_urls () {
71 (
72 root=$(pwd) &&
73 cd super-clone/submodule &&
74 git config remote.origin.url "$root/submodule"
75 ) &&
76 (
77 root=$(pwd) &&
78 cd super-clone/submodule/sub-submodule &&
79 git config remote.origin.url "$root/submodule"
80 )
81 }
82
83 test_expect_success 'change submodule url' '
84 (
85 cd super &&
86 cd submodule &&
87 git checkout main &&
88 git pull
89 ) &&
90 mv submodule moved-submodule &&
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
96 ) &&
97 (
98 cd super &&
99 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
100 test_tick &&
101 git commit -a -m moved-submodule
102 )
103 '
104
105 test_expect_success '"git submodule sync" should update submodule URLs' '
106 (
107 cd super-clone &&
108 git pull --no-recurse-submodules &&
109 git submodule sync
110 ) &&
111 test -d "$(
112 cd super-clone/submodule &&
113 git config remote.origin.url
114 )" &&
115 test ! -d "$(
116 cd super-clone/submodule/sub-submodule &&
117 git config remote.origin.url
118 )" &&
119 (
120 cd super-clone/submodule &&
121 git checkout main &&
122 git pull
123 ) &&
124 (
125 cd super-clone &&
126 test -d "$(git config submodule.submodule.url)"
127 )
128 '
129
130 test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
131 (
132 cd super-clone &&
133 (
134 cd submodule &&
135 git pull --no-recurse-submodules
136 ) &&
137 git submodule sync --recursive
138 ) &&
139 test -d "$(
140 cd super-clone/submodule &&
141 git config remote.origin.url
142 )" &&
143 test -d "$(
144 cd super-clone/submodule/sub-submodule &&
145 git config remote.origin.url
146 )" &&
147 (
148 cd super-clone/submodule/sub-submodule &&
149 git checkout main &&
150 git pull
151 )
152 '
153
154 test_expect_success 'reset submodule URLs' '
155 reset_submodule_urls super-clone
156 '
157
158 test_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 ) &&
166 test_grep "\\.\\./submodule" output &&
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 &&
177 git checkout main &&
178 git pull
179 ) &&
180 (
181 cd super-clone &&
182 test -d "$(git config submodule.submodule.url)"
183 )
184 '
185
186 test_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 ) &&
197 test_grep "\\.\\./submodule/sub-submodule" output &&
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 &&
208 git checkout main &&
209 git pull
210 )
211 '
212
213 test_expect_success '"git submodule sync" should update known submodule URLs' '
214 (
215 cd empty-clone &&
216 git pull &&
217 git submodule sync &&
218 test -d "$(git config submodule.submodule.url)"
219 )
220 '
221
222 test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
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)"
230 )
231 '
232
233 test_expect_success '"git submodule sync" handles origin URL of the form foo' '
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 )
243 )
244 '
245
246 test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
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"
255 ) &&
256 (
257 cd submodule/sub-submodule &&
258 test "$(git config remote.origin.url)" != "../../foo/submodule"
259 )
260 )
261 '
262
263 test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
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"
272 ) &&
273 (
274 cd submodule/sub-submodule &&
275 test "$(git config remote.origin.url)" = "../../foo/submodule"
276 )
277 )
278 '
279
280 test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
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 )
290 )
291 '
292
293 test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
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 )
303 )
304 '
305
306 test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
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 )
316 )
317 '
318
319 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
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 )
329 )
330 '
331
332 test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
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 )
352 )
353 '
354
355
356 test_done