Merge branch 'sp/maint-http-backend-die-triggers-die-recursively'
[git/jnareb-git.git] / t / t7406-submodule-update.sh
blob1382a8e58a14c8fcc92889aad492d5883fd64f2b
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 --rebase staying on master' '
78 (cd super/submodule &&
79 git checkout master
80 ) &&
81 (cd super &&
82 (cd submodule &&
83 compare_head
84 ) &&
85 git submodule update --rebase submodule &&
86 cd submodule &&
87 compare_head
91 test_expect_success 'submodule update --merge staying on master' '
92 (cd super/submodule &&
93 git reset --hard HEAD~1
94 ) &&
95 (cd super &&
96 (cd submodule &&
97 compare_head
98 ) &&
99 git submodule update --merge submodule &&
100 cd submodule &&
101 compare_head
105 test_expect_success 'submodule update - rebase in .git/config' '
106 (cd super &&
107 git config submodule.submodule.update rebase
108 ) &&
109 (cd super/submodule &&
110 git reset --hard HEAD~1
111 ) &&
112 (cd super &&
113 (cd submodule &&
114 compare_head
115 ) &&
116 git submodule update submodule &&
117 cd submodule &&
118 compare_head
122 test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
123 (cd super &&
124 git config submodule.submodule.update checkout
125 ) &&
126 (cd super/submodule &&
127 git reset --hard HEAD~1
128 ) &&
129 (cd super &&
130 (cd submodule &&
131 compare_head
132 ) &&
133 git submodule update --rebase submodule &&
134 cd submodule &&
135 compare_head
139 test_expect_success 'submodule update - merge in .git/config' '
140 (cd super &&
141 git config submodule.submodule.update merge
142 ) &&
143 (cd super/submodule &&
144 git reset --hard HEAD~1
145 ) &&
146 (cd super &&
147 (cd submodule &&
148 compare_head
149 ) &&
150 git submodule update submodule &&
151 cd submodule &&
152 compare_head
156 test_expect_success 'submodule update - checkout in .git/config but --merge given' '
157 (cd super &&
158 git config submodule.submodule.update checkout
159 ) &&
160 (cd super/submodule &&
161 git reset --hard HEAD~1
162 ) &&
163 (cd super &&
164 (cd submodule &&
165 compare_head
166 ) &&
167 git submodule update --merge submodule &&
168 cd submodule &&
169 compare_head
173 test_expect_success 'submodule update - checkout in .git/config' '
174 (cd super &&
175 git config submodule.submodule.update checkout
176 ) &&
177 (cd super/submodule &&
178 git reset --hard HEAD^
179 ) &&
180 (cd super &&
181 (cd submodule &&
182 compare_head
183 ) &&
184 git submodule update submodule &&
185 cd submodule &&
186 ! compare_head
190 test_expect_success 'submodule init picks up rebase' '
191 (cd super &&
192 git config -f .gitmodules submodule.rebasing.update rebase &&
193 git submodule init rebasing &&
194 test "rebase" = "$(git config submodule.rebasing.update)"
198 test_expect_success 'submodule init picks up merge' '
199 (cd super &&
200 git config -f .gitmodules submodule.merging.update merge &&
201 git submodule init merging &&
202 test "merge" = "$(git config submodule.merging.update)"
206 test_done