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