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.
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' '
28 git commit -m upstream &&
30 git clone super submodule &&
31 git clone super rebasing &&
32 git clone super merging &&
34 git submodule add ../submodule submodule &&
36 git commit -m "submodule" &&
37 git submodule init submodule
40 echo "line2" > file &&
42 git commit -m "Commit 2"
46 git pull --rebase origin
49 git commit -m "submodule update"
52 git submodule add ../rebasing rebasing &&
54 git commit -m "rebasing"
57 git submodule add ../merging merging &&
59 git commit -m "rebasing"
63 test_expect_success
'submodule update detaching the HEAD ' '
64 (cd super/submodule &&
65 git reset --hard HEAD~1
71 git submodule update submodule &&
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
86 test_must_fail git submodule update submodule
89 test_expect_success
'submodule update should throw away changes with --force ' '
94 git submodule update --force submodule &&
100 test_expect_success
'submodule update --rebase staying on master' '
101 (cd super/submodule &&
108 git submodule update --rebase submodule &&
114 test_expect_success
'submodule update --merge staying on master' '
115 (cd super/submodule &&
116 git reset --hard HEAD~1
122 git submodule update --merge submodule &&
128 test_expect_success
'submodule update - rebase in .git/config' '
130 git config submodule.submodule.update rebase
132 (cd super/submodule &&
133 git reset --hard HEAD~1
139 git submodule update submodule &&
145 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
147 git config submodule.submodule.update checkout
149 (cd super/submodule &&
150 git reset --hard HEAD~1
156 git submodule update --rebase submodule &&
162 test_expect_success
'submodule update - merge in .git/config' '
164 git config submodule.submodule.update merge
166 (cd super/submodule &&
167 git reset --hard HEAD~1
173 git submodule update submodule &&
179 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
181 git config submodule.submodule.update checkout
183 (cd super/submodule &&
184 git reset --hard HEAD~1
190 git submodule update --merge submodule &&
196 test_expect_success
'submodule update - checkout in .git/config' '
198 git config submodule.submodule.update checkout
200 (cd super/submodule &&
201 git reset --hard HEAD^
207 git submodule update submodule &&
213 test_expect_success
'submodule init picks up rebase' '
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' '
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' '
232 git submodule update submodule &&
233 git status -s submodule >expect &&
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' '
244 git submodule update submodule &&
245 git status -s submodule >expect &&
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' '
256 git submodule update submodule &&
257 git status -s submodule >expect &&
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' '
270 git submodule update submodule &&
271 git status -s submodule >expect &&
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