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 --rebase staying on master' '
98 (cd super/submodule &&
105 git submodule update --rebase submodule &&
111 test_expect_success
'submodule update --merge staying on master' '
112 (cd super/submodule &&
113 git reset --hard HEAD~1
119 git submodule update --merge submodule &&
125 test_expect_success
'submodule update - rebase in .git/config' '
127 git config submodule.submodule.update rebase
129 (cd super/submodule &&
130 git reset --hard HEAD~1
136 git submodule update submodule &&
142 test_expect_success
'submodule update - checkout in .git/config but --rebase given' '
144 git config submodule.submodule.update checkout
146 (cd super/submodule &&
147 git reset --hard HEAD~1
153 git submodule update --rebase submodule &&
159 test_expect_success
'submodule update - merge in .git/config' '
161 git config submodule.submodule.update merge
163 (cd super/submodule &&
164 git reset --hard HEAD~1
170 git submodule update submodule &&
176 test_expect_success
'submodule update - checkout in .git/config but --merge given' '
178 git config submodule.submodule.update checkout
180 (cd super/submodule &&
181 git reset --hard HEAD~1
187 git submodule update --merge submodule &&
193 test_expect_success
'submodule update - checkout in .git/config' '
195 git config submodule.submodule.update checkout
197 (cd super/submodule &&
198 git reset --hard HEAD^
204 git submodule update submodule &&
210 test_expect_success
'submodule init picks up rebase' '
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' '
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' '
229 git submodule update submodule &&
230 git status -s submodule >expect &&
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' '
241 git submodule update submodule &&
242 git status -s submodule >expect &&
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' '
253 git submodule update submodule &&
254 git status -s submodule >expect &&
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' '
267 git submodule update submodule &&
268 git status -s submodule >expect &&
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