]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7406-submodule-update.sh
rev-parse: add option --resolve-git-dir <path>
[thirdparty/git.git] / t / t7406-submodule-update.sh
CommitLineData
ca2cedba
PH
1#!/bin/sh
2#
3# Copyright (c) 2009 Red Hat, Inc.
4#
5
6test_description='Test updating submodules
7
8This test verifies that "git submodule update" detaches the HEAD of the
42b49178 9submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
ca2cedba
PH
10'
11
12. ./test-lib.sh
13
14
15compare_head()
16{
5d59a401
MO
17 sha_master=`git rev-list --max-count=1 master`
18 sha_head=`git rev-list --max-count=1 HEAD`
ca2cedba
PH
19
20 test "$sha_master" = "$sha_head"
21}
22
23
24test_expect_success 'setup a submodule tree' '
25 echo file > file &&
26 git add file &&
27 test_tick &&
4bf9dd97 28 git commit -m upstream &&
ca2cedba
PH
29 git clone . super &&
30 git clone super submodule &&
c9c8c56e
SB
31 git clone super rebasing &&
32 git clone super merging &&
ca2cedba
PH
33 (cd super &&
34 git submodule add ../submodule submodule &&
35 test_tick &&
36 git commit -m "submodule" &&
37 git submodule init submodule
38 ) &&
39 (cd submodule &&
40 echo "line2" > file &&
41 git add file &&
42 git commit -m "Commit 2"
43 ) &&
44 (cd super &&
45 (cd submodule &&
46 git pull --rebase origin
47 ) &&
48 git add submodule &&
49 git commit -m "submodule update"
c9c8c56e
SB
50 ) &&
51 (cd super &&
52 git submodule add ../rebasing rebasing &&
53 test_tick &&
54 git commit -m "rebasing"
55 ) &&
56 (cd super &&
57 git submodule add ../merging merging &&
58 test_tick &&
59 git commit -m "rebasing"
ca2cedba
PH
60 )
61'
62
63test_expect_success 'submodule update detaching the HEAD ' '
64 (cd super/submodule &&
65 git reset --hard HEAD~1
66 ) &&
67 (cd super &&
68 (cd submodule &&
69 compare_head
70 ) &&
71 git submodule update submodule &&
72 cd submodule &&
73 ! compare_head
74 )
75'
76
e5f522d6
JL
77apos="'";
78test_expect_success 'submodule update does not fetch already present commits' '
79 (cd submodule &&
80 echo line3 >> file &&
81 git add file &&
82 test_tick &&
83 git commit -m "upstream line3"
84 ) &&
85 (cd super/submodule &&
86 head=$(git rev-parse --verify HEAD) &&
87 echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
88 git reset --hard HEAD~1
89 ) &&
90 (cd super &&
91 git submodule update > ../actual 2> ../actual.err
92 ) &&
ee653c89 93 test_i18ncmp expected actual &&
e5f522d6
JL
94 ! test -s actual.err
95'
96
9db31bdf
NMC
97test_expect_success 'submodule update should fail due to local changes' '
98 (cd super/submodule &&
99 git reset --hard HEAD~1 &&
100 echo "local change" > file
101 ) &&
102 (cd super &&
103 (cd submodule &&
104 compare_head
105 ) &&
106 test_must_fail git submodule update submodule
107 )
108'
109test_expect_success 'submodule update should throw away changes with --force ' '
110 (cd super &&
111 (cd submodule &&
112 compare_head
113 ) &&
114 git submodule update --force submodule &&
115 cd submodule &&
116 ! compare_head
117 )
118'
119
ca2cedba
PH
120test_expect_success 'submodule update --rebase staying on master' '
121 (cd super/submodule &&
122 git checkout master
123 ) &&
124 (cd super &&
125 (cd submodule &&
126 compare_head
127 ) &&
128 git submodule update --rebase submodule &&
129 cd submodule &&
130 compare_head
131 )
132'
133
42b49178
JH
134test_expect_success 'submodule update --merge staying on master' '
135 (cd super/submodule &&
136 git reset --hard HEAD~1
137 ) &&
138 (cd super &&
139 (cd submodule &&
140 compare_head
141 ) &&
142 git submodule update --merge submodule &&
143 cd submodule &&
144 compare_head
145 )
146'
147
32948425 148test_expect_success 'submodule update - rebase in .git/config' '
ca2cedba 149 (cd super &&
32948425 150 git config submodule.submodule.update rebase
ca2cedba
PH
151 ) &&
152 (cd super/submodule &&
153 git reset --hard HEAD~1
154 ) &&
155 (cd super &&
156 (cd submodule &&
157 compare_head
158 ) &&
159 git submodule update submodule &&
160 cd submodule &&
161 compare_head
162 )
163'
164
32948425 165test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
ca2cedba 166 (cd super &&
32948425 167 git config submodule.submodule.update checkout
ca2cedba
PH
168 ) &&
169 (cd super/submodule &&
170 git reset --hard HEAD~1
171 ) &&
172 (cd super &&
173 (cd submodule &&
174 compare_head
175 ) &&
176 git submodule update --rebase submodule &&
177 cd submodule &&
178 compare_head
179 )
180'
181
42b49178
JH
182test_expect_success 'submodule update - merge in .git/config' '
183 (cd super &&
184 git config submodule.submodule.update merge
185 ) &&
186 (cd super/submodule &&
187 git reset --hard HEAD~1
188 ) &&
189 (cd super &&
190 (cd submodule &&
191 compare_head
192 ) &&
193 git submodule update submodule &&
194 cd submodule &&
195 compare_head
196 )
197'
198
199test_expect_success 'submodule update - checkout in .git/config but --merge given' '
200 (cd super &&
201 git config submodule.submodule.update checkout
202 ) &&
203 (cd super/submodule &&
204 git reset --hard HEAD~1
205 ) &&
206 (cd super &&
207 (cd submodule &&
208 compare_head
209 ) &&
210 git submodule update --merge submodule &&
211 cd submodule &&
212 compare_head
213 )
214'
215
32948425 216test_expect_success 'submodule update - checkout in .git/config' '
ca2cedba 217 (cd super &&
32948425 218 git config submodule.submodule.update checkout
ca2cedba
PH
219 ) &&
220 (cd super/submodule &&
221 git reset --hard HEAD^
222 ) &&
223 (cd super &&
224 (cd submodule &&
225 compare_head
226 ) &&
227 git submodule update submodule &&
228 cd submodule &&
229 ! compare_head
230 )
231'
232
233test_expect_success 'submodule init picks up rebase' '
234 (cd super &&
c9c8c56e 235 git config -f .gitmodules submodule.rebasing.update rebase &&
ca2cedba 236 git submodule init rebasing &&
c9c8c56e 237 test "rebase" = "$(git config submodule.rebasing.update)"
ca2cedba
PH
238 )
239'
240
42b49178
JH
241test_expect_success 'submodule init picks up merge' '
242 (cd super &&
c9c8c56e 243 git config -f .gitmodules submodule.merging.update merge &&
42b49178 244 git submodule init merging &&
c9c8c56e 245 test "merge" = "$(git config submodule.merging.update)"
42b49178
JH
246 )
247'
248
b200021e
SO
249test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
250 (cd super &&
251 rm -rf submodule &&
252 git submodule update submodule &&
253 git status -s submodule >expect &&
254 rm -rf submodule &&
255 git submodule update --merge submodule &&
256 git status -s submodule >actual &&
257 test_cmp expect actual
258 )
259'
260
261test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
262 (cd super &&
263 rm -rf submodule &&
264 git submodule update submodule &&
265 git status -s submodule >expect &&
266 rm -rf submodule &&
267 git submodule update --rebase submodule &&
268 git status -s submodule >actual &&
269 test_cmp expect actual
270 )
271'
272
273test_expect_success 'submodule update ignores update=merge config for new submodules' '
274 (cd super &&
275 rm -rf submodule &&
276 git submodule update submodule &&
277 git status -s submodule >expect &&
278 rm -rf submodule &&
279 git config submodule.submodule.update merge &&
280 git submodule update submodule &&
281 git status -s submodule >actual &&
282 git config --unset submodule.submodule.update &&
283 test_cmp expect actual
284 )
285'
286
287test_expect_success 'submodule update ignores update=rebase config for new submodules' '
288 (cd super &&
289 rm -rf submodule &&
290 git submodule update submodule &&
291 git status -s submodule >expect &&
292 rm -rf submodule &&
293 git config submodule.submodule.update rebase &&
294 git submodule update submodule &&
295 git status -s submodule >actual &&
296 git config --unset submodule.submodule.update &&
297 test_cmp expect actual
298 )
299'
300
15ffb7cd
FG
301test_expect_success 'submodule update continues after checkout error' '
302 (cd super &&
303 git reset --hard HEAD &&
304 git submodule add ../submodule submodule2 &&
305 git submodule init &&
306 git commit -am "new_submodule" &&
307 (cd submodule2 &&
308 git rev-parse --max-count=1 HEAD > ../expect
309 ) &&
310 (cd submodule &&
311 test_commit "update_submodule" file
312 ) &&
313 (cd submodule2 &&
314 test_commit "update_submodule2" file
315 ) &&
316 git add submodule &&
317 git add submodule2 &&
318 git commit -m "two_new_submodule_commits" &&
319 (cd submodule &&
320 echo "" > file
321 ) &&
322 git checkout HEAD^ &&
323 test_must_fail git submodule update &&
324 (cd submodule2 &&
325 git rev-parse --max-count=1 HEAD > ../actual
326 ) &&
327 test_cmp expect actual
328 )
329'
330test_expect_success 'submodule update continues after recursive checkout error' '
331 (cd super &&
332 git reset --hard HEAD &&
333 git checkout master &&
334 git submodule update &&
335 (cd submodule &&
336 git submodule add ../submodule subsubmodule &&
337 git submodule init &&
338 git commit -m "new_subsubmodule"
339 ) &&
340 git add submodule &&
341 git commit -m "update_submodule" &&
342 (cd submodule &&
343 (cd subsubmodule &&
344 test_commit "update_subsubmodule" file
345 ) &&
346 git add subsubmodule &&
347 test_commit "update_submodule_again" file &&
348 (cd subsubmodule &&
349 test_commit "update_subsubmodule_again" file
350 ) &&
351 test_commit "update_submodule_again_again" file
352 ) &&
353 (cd submodule2 &&
354 git rev-parse --max-count=1 HEAD > ../expect &&
355 test_commit "update_submodule2_again" file
356 ) &&
357 git add submodule &&
358 git add submodule2 &&
359 git commit -m "new_commits" &&
360 git checkout HEAD^ &&
361 (cd submodule &&
362 git checkout HEAD^ &&
363 (cd subsubmodule &&
364 echo "" > file
365 )
366 ) &&
367 test_must_fail git submodule update --recursive &&
368 (cd submodule2 &&
369 git rev-parse --max-count=1 HEAD > ../actual
370 ) &&
371 test_cmp expect actual
372 )
373'
374
375test_expect_success 'submodule update exit immediately in case of merge conflict' '
376 (cd super &&
377 git checkout master &&
378 git reset --hard HEAD &&
379 (cd submodule &&
380 (cd subsubmodule &&
381 git reset --hard HEAD
382 )
383 ) &&
384 git submodule update --recursive &&
385 (cd submodule &&
386 test_commit "update_submodule_2" file
387 ) &&
388 (cd submodule2 &&
389 test_commit "update_submodule2_2" file
390 ) &&
391 git add submodule &&
392 git add submodule2 &&
393 git commit -m "two_new_submodule_commits" &&
394 (cd submodule &&
395 git checkout master &&
396 test_commit "conflict" file &&
397 echo "conflict" > file
398 ) &&
399 git checkout HEAD^ &&
400 (cd submodule2 &&
401 git rev-parse --max-count=1 HEAD > ../expect
402 ) &&
403 git config submodule.submodule.update merge &&
404 test_must_fail git submodule update &&
405 (cd submodule2 &&
406 git rev-parse --max-count=1 HEAD > ../actual
407 ) &&
408 test_cmp expect actual
409 )
410'
411test_expect_success 'submodule update exit immediately after recursive rebase error' '
412 (cd super &&
413 git checkout master &&
414 git reset --hard HEAD &&
415 (cd submodule &&
416 git reset --hard HEAD &&
417 git submodule update --recursive
418 ) &&
419 (cd submodule &&
420 test_commit "update_submodule_3" file
421 ) &&
422 (cd submodule2 &&
423 test_commit "update_submodule2_3" file
424 ) &&
425 git add submodule &&
426 git add submodule2 &&
427 git commit -m "two_new_submodule_commits" &&
428 (cd submodule &&
429 git checkout master &&
430 test_commit "conflict2" file &&
431 echo "conflict" > file
432 ) &&
433 git checkout HEAD^ &&
434 (cd submodule2 &&
435 git rev-parse --max-count=1 HEAD > ../expect
436 ) &&
437 git config submodule.submodule.update rebase &&
438 test_must_fail git submodule update &&
439 (cd submodule2 &&
440 git rev-parse --max-count=1 HEAD > ../actual
441 ) &&
442 test_cmp expect actual
443 )
444'
ca2cedba 445test_done