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 &&
78 test_expect_success 'submodule update does not fetch already present commits' '
83 git commit -m "upstream line3"
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
91 git submodule update > ../actual 2> ../actual.err
93 test_cmp expected actual &&
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
106 test_must_fail git submodule update submodule
109 test_expect_success 'submodule update should throw away changes with --force ' '
114 git submodule update --force submodule &&
120 test_expect_success 'submodule update --rebase staying on master' '
121 (cd super/submodule &&
128 git submodule update --rebase submodule &&
134 test_expect_success 'submodule update --merge staying on master' '
135 (cd super/submodule &&
136 git reset --hard HEAD~1
142 git submodule update --merge submodule &&
148 test_expect_success 'submodule update - rebase in .git/config' '
150 git config submodule.submodule.update rebase
152 (cd super/submodule &&
153 git reset --hard HEAD~1
159 git submodule update submodule &&
165 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
167 git config submodule.submodule.update checkout
169 (cd super/submodule &&
170 git reset --hard HEAD~1
176 git submodule update --rebase submodule &&
182 test_expect_success 'submodule update - merge in .git/config' '
184 git config submodule.submodule.update merge
186 (cd super/submodule &&
187 git reset --hard HEAD~1
193 git submodule update submodule &&
199 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
201 git config submodule.submodule.update checkout
203 (cd super/submodule &&
204 git reset --hard HEAD~1
210 git submodule update --merge submodule &&
216 test_expect_success 'submodule update - checkout in .git/config' '
218 git config submodule.submodule.update checkout
220 (cd super/submodule &&
221 git reset --hard HEAD^
227 git submodule update submodule &&
233 test_expect_success 'submodule init picks up rebase' '
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' '
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' '
252 git submodule update submodule &&
253 git status -s submodule >expect &&
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' '
264 git submodule update submodule &&
265 git status -s submodule >expect &&
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' '
276 git submodule update submodule &&
277 git status -s submodule >expect &&
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' '
290 git submodule update submodule &&
291 git status -s submodule >expect &&
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