submodule: Add --force option for git submodule update
[alt-git.git] / t / t7406-submodule-update.sh
blob5d24d9ff74595174a4549bb165fcc8a0800d8120
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 test_expect_success 'submodule update should fail due to local changes' '
78 (cd super/submodule &&
79 git reset --hard HEAD~1 &&
80 echo "local change" > file
81 ) &&
82 (cd super &&
83 (cd submodule &&
84 compare_head
85 ) &&
86 test_must_fail git submodule update submodule
89 test_expect_success 'submodule update should throw away changes with --force ' '
90 (cd super &&
91 (cd submodule &&
92 compare_head
93 ) &&
94 git submodule update --force submodule &&
95 cd submodule &&
96 ! compare_head
100 test_expect_success 'submodule update --rebase staying on master' '
101 (cd super/submodule &&
102 git checkout master
103 ) &&
104 (cd super &&
105 (cd submodule &&
106 compare_head
107 ) &&
108 git submodule update --rebase submodule &&
109 cd submodule &&
110 compare_head
114 test_expect_success 'submodule update --merge staying on master' '
115 (cd super/submodule &&
116 git reset --hard HEAD~1
117 ) &&
118 (cd super &&
119 (cd submodule &&
120 compare_head
121 ) &&
122 git submodule update --merge submodule &&
123 cd submodule &&
124 compare_head
128 test_expect_success 'submodule update - rebase in .git/config' '
129 (cd super &&
130 git config submodule.submodule.update rebase
131 ) &&
132 (cd super/submodule &&
133 git reset --hard HEAD~1
134 ) &&
135 (cd super &&
136 (cd submodule &&
137 compare_head
138 ) &&
139 git submodule update submodule &&
140 cd submodule &&
141 compare_head
145 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
146 (cd super &&
147 git config submodule.submodule.update checkout
148 ) &&
149 (cd super/submodule &&
150 git reset --hard HEAD~1
151 ) &&
152 (cd super &&
153 (cd submodule &&
154 compare_head
155 ) &&
156 git submodule update --rebase submodule &&
157 cd submodule &&
158 compare_head
162 test_expect_success 'submodule update - merge in .git/config' '
163 (cd super &&
164 git config submodule.submodule.update merge
165 ) &&
166 (cd super/submodule &&
167 git reset --hard HEAD~1
168 ) &&
169 (cd super &&
170 (cd submodule &&
171 compare_head
172 ) &&
173 git submodule update submodule &&
174 cd submodule &&
175 compare_head
179 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
180 (cd super &&
181 git config submodule.submodule.update checkout
182 ) &&
183 (cd super/submodule &&
184 git reset --hard HEAD~1
185 ) &&
186 (cd super &&
187 (cd submodule &&
188 compare_head
189 ) &&
190 git submodule update --merge submodule &&
191 cd submodule &&
192 compare_head
196 test_expect_success 'submodule update - checkout in .git/config' '
197 (cd super &&
198 git config submodule.submodule.update checkout
199 ) &&
200 (cd super/submodule &&
201 git reset --hard HEAD^
202 ) &&
203 (cd super &&
204 (cd submodule &&
205 compare_head
206 ) &&
207 git submodule update submodule &&
208 cd submodule &&
209 ! compare_head
213 test_expect_success 'submodule init picks up rebase' '
214 (cd super &&
215 git config -f .gitmodules submodule.rebasing.update rebase &&
216 git submodule init rebasing &&
217 test "rebase" = "$(git config submodule.rebasing.update)"
221 test_expect_success 'submodule init picks up merge' '
222 (cd super &&
223 git config -f .gitmodules submodule.merging.update merge &&
224 git submodule init merging &&
225 test "merge" = "$(git config submodule.merging.update)"
229 test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
230 (cd super &&
231 rm -rf submodule &&
232 git submodule update submodule &&
233 git status -s submodule >expect &&
234 rm -rf submodule &&
235 git submodule update --merge submodule &&
236 git status -s submodule >actual &&
237 test_cmp expect actual
241 test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
242 (cd super &&
243 rm -rf submodule &&
244 git submodule update submodule &&
245 git status -s submodule >expect &&
246 rm -rf submodule &&
247 git submodule update --rebase submodule &&
248 git status -s submodule >actual &&
249 test_cmp expect actual
253 test_expect_success 'submodule update ignores update=merge config for new submodules' '
254 (cd super &&
255 rm -rf submodule &&
256 git submodule update submodule &&
257 git status -s submodule >expect &&
258 rm -rf submodule &&
259 git config submodule.submodule.update merge &&
260 git submodule update submodule &&
261 git status -s submodule >actual &&
262 git config --unset submodule.submodule.update &&
263 test_cmp expect actual
267 test_expect_success 'submodule update ignores update=rebase config for new submodules' '
268 (cd super &&
269 rm -rf submodule &&
270 git submodule update submodule &&
271 git status -s submodule >expect &&
272 rm -rf submodule &&
273 git config submodule.submodule.update rebase &&
274 git submodule update submodule &&
275 git status -s submodule >actual &&
276 git config --unset submodule.submodule.update &&
277 test_cmp expect actual
281 test_done