Merge git://git.kernel.org/pub/scm/gitk/gitk
[git/jrn.git] / t / t7406-submodule-update.sh
blobbf7c788735d6e3e0ecf56e7a2f82826701ee1789
1 #!/bin/sh
3 # Copyright (c) 2009 Red Hat, Inc.
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.
12 . ./test-lib.sh
15 compare_head()
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"
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"
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
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_cmp expected actual &&
94 ! test -s actual.err
97 test_expect_success 'submodule update --rebase staying on master' '
98 (cd super/submodule &&
99 git checkout master
100 ) &&
101 (cd super &&
102 (cd submodule &&
103 compare_head
104 ) &&
105 git submodule update --rebase submodule &&
106 cd submodule &&
107 compare_head
111 test_expect_success 'submodule update --merge staying on master' '
112 (cd super/submodule &&
113 git reset --hard HEAD~1
114 ) &&
115 (cd super &&
116 (cd submodule &&
117 compare_head
118 ) &&
119 git submodule update --merge submodule &&
120 cd submodule &&
121 compare_head
125 test_expect_success 'submodule update - rebase in .git/config' '
126 (cd super &&
127 git config submodule.submodule.update rebase
128 ) &&
129 (cd super/submodule &&
130 git reset --hard HEAD~1
131 ) &&
132 (cd super &&
133 (cd submodule &&
134 compare_head
135 ) &&
136 git submodule update submodule &&
137 cd submodule &&
138 compare_head
142 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
143 (cd super &&
144 git config submodule.submodule.update checkout
145 ) &&
146 (cd super/submodule &&
147 git reset --hard HEAD~1
148 ) &&
149 (cd super &&
150 (cd submodule &&
151 compare_head
152 ) &&
153 git submodule update --rebase submodule &&
154 cd submodule &&
155 compare_head
159 test_expect_success 'submodule update - merge in .git/config' '
160 (cd super &&
161 git config submodule.submodule.update merge
162 ) &&
163 (cd super/submodule &&
164 git reset --hard HEAD~1
165 ) &&
166 (cd super &&
167 (cd submodule &&
168 compare_head
169 ) &&
170 git submodule update submodule &&
171 cd submodule &&
172 compare_head
176 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
177 (cd super &&
178 git config submodule.submodule.update checkout
179 ) &&
180 (cd super/submodule &&
181 git reset --hard HEAD~1
182 ) &&
183 (cd super &&
184 (cd submodule &&
185 compare_head
186 ) &&
187 git submodule update --merge submodule &&
188 cd submodule &&
189 compare_head
193 test_expect_success 'submodule update - checkout in .git/config' '
194 (cd super &&
195 git config submodule.submodule.update checkout
196 ) &&
197 (cd super/submodule &&
198 git reset --hard HEAD^
199 ) &&
200 (cd super &&
201 (cd submodule &&
202 compare_head
203 ) &&
204 git submodule update submodule &&
205 cd submodule &&
206 ! compare_head
210 test_expect_success 'submodule init picks up rebase' '
211 (cd super &&
212 git config -f .gitmodules submodule.rebasing.update rebase &&
213 git submodule init rebasing &&
214 test "rebase" = "$(git config submodule.rebasing.update)"
218 test_expect_success 'submodule init picks up merge' '
219 (cd super &&
220 git config -f .gitmodules submodule.merging.update merge &&
221 git submodule init merging &&
222 test "merge" = "$(git config submodule.merging.update)"
226 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
227 (cd super &&
228 rm -rf submodule &&
229 git submodule update submodule &&
230 git status -s submodule >expect &&
231 rm -rf submodule &&
232 git submodule update --merge submodule &&
233 git status -s submodule >actual &&
234 test_cmp expect actual
238 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
239 (cd super &&
240 rm -rf submodule &&
241 git submodule update submodule &&
242 git status -s submodule >expect &&
243 rm -rf submodule &&
244 git submodule update --rebase submodule &&
245 git status -s submodule >actual &&
246 test_cmp expect actual
250 test_expect_success 'submodule update ignores update=merge config for new submodules' '
251 (cd super &&
252 rm -rf submodule &&
253 git submodule update submodule &&
254 git status -s submodule >expect &&
255 rm -rf submodule &&
256 git config submodule.submodule.update merge &&
257 git submodule update submodule &&
258 git status -s submodule >actual &&
259 git config --unset submodule.submodule.update &&
260 test_cmp expect actual
264 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
265 (cd super &&
266 rm -rf submodule &&
267 git submodule update submodule &&
268 git status -s submodule >expect &&
269 rm -rf submodule &&
270 git config submodule.submodule.update rebase &&
271 git submodule update submodule &&
272 git status -s submodule >actual &&
273 git config --unset submodule.submodule.update &&
274 test_cmp expect actual
278 test_done