clone: allow to clone from .git file
[git/gitweb.git] / t / t7406-submodule-update.sh
blob4f16fcce2bfcb63f437fa6b495fdb5c4370fccc1
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 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
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
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
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
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
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
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
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
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
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)"
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)"
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
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
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
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
301 test_done