Code

diff-index: enable recursive pathspec matching in unpack_trees
[git.git] / t / t7406-submodule-update.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Red Hat, Inc.
4 #
6 test_description='Test updating submodules
8 This test verifies that "git submodule update" detaches the HEAD of the
9 submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
10 '
12 . ./test-lib.sh
15 compare_head()
16 {
17     sha_master=`git rev-list --max-count=1 master`
18     sha_head=`git rev-list --max-count=1 HEAD`
20     test "$sha_master" = "$sha_head"
21 }
24 test_expect_success 'setup a submodule tree' '
25         echo file > file &&
26         git add file &&
27         test_tick &&
28         git commit -m upstream &&
29         git clone . super &&
30         git clone super submodule &&
31         git clone super rebasing &&
32         git clone super merging &&
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"
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"
60         )
61 '
63 test_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 '
77 apos="'";
78 test_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         ) &&
93         test_i18ncmp expected actual &&
94         ! test -s actual.err
95 '
97 test_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         )
109 test_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         )
120 test_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         )
134 test_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         )
148 test_expect_success 'submodule update - rebase in .git/config' '
149         (cd super &&
150          git config submodule.submodule.update rebase
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         )
165 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
166         (cd super &&
167          git config submodule.submodule.update checkout
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         )
182 test_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         )
199 test_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         )
216 test_expect_success 'submodule update - checkout in .git/config' '
217         (cd super &&
218          git config submodule.submodule.update checkout
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         )
233 test_expect_success 'submodule init picks up rebase' '
234         (cd super &&
235          git config -f .gitmodules submodule.rebasing.update rebase &&
236          git submodule init rebasing &&
237          test "rebase" = "$(git config submodule.rebasing.update)"
238         )
241 test_expect_success 'submodule init picks up merge' '
242         (cd super &&
243          git config -f .gitmodules submodule.merging.update merge &&
244          git submodule init merging &&
245          test "merge" = "$(git config submodule.merging.update)"
246         )
249 test_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         )
261 test_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         )
273 test_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         )
287 test_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         )
301 test_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         )
330 test_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         )
375 test_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         )
411 test_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         )
445 test_done