]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7407-submodule-foreach.sh
submodule: only preserve flags across recursive status/update invocations
[thirdparty/git.git] / t / t7407-submodule-foreach.sh
CommitLineData
d69ecf6f
JH
1#!/bin/sh
2#
3# Copyright (c) 2009 Johan Herland
4#
5
6test_description='Test "git submodule foreach"
7
8This test verifies that "git submodule foreach" correctly visits all submodules
9that are currently checked out.
10'
11
12. ./test-lib.sh
13
14
15test_expect_success 'setup a submodule tree' '
16 echo file > file &&
17 git add file &&
18 test_tick &&
4bf9dd97 19 git commit -m upstream &&
d69ecf6f
JH
20 git clone . super &&
21 git clone super submodule &&
22 (
23 cd super &&
24 git submodule add ../submodule sub1 &&
25 git submodule add ../submodule sub2 &&
26 git submodule add ../submodule sub3 &&
27 git config -f .gitmodules --rename-section \
28 submodule.sub1 submodule.foo1 &&
29 git config -f .gitmodules --rename-section \
30 submodule.sub2 submodule.foo2 &&
31 git config -f .gitmodules --rename-section \
32 submodule.sub3 submodule.foo3 &&
4bf9dd97 33 git add .gitmodules &&
d69ecf6f
JH
34 test_tick &&
35 git commit -m "submodules" &&
36 git submodule init sub1 &&
37 git submodule init sub2 &&
38 git submodule init sub3
39 ) &&
40 (
41 cd submodule &&
42 echo different > file &&
43 git add file &&
44 test_tick &&
45 git commit -m "different"
46 ) &&
47 (
48 cd super &&
49 (
50 cd sub3 &&
51 git pull
52 ) &&
53 git add sub3 &&
54 test_tick &&
55 git commit -m "update sub3"
56 )
57'
58
59sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
60sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
61
f030c96d
ÆAB
62pwd=$(pwd)
63
d69ecf6f
JH
64cat > expect <<EOF
65Entering 'sub1'
f030c96d 66$pwd/clone-foo1-sub1-$sub1sha1
d69ecf6f 67Entering 'sub3'
f030c96d 68$pwd/clone-foo3-sub3-$sub3sha1
d69ecf6f
JH
69EOF
70
71test_expect_success 'test basic "submodule foreach" usage' '
72 git clone super clone &&
73 (
74 cd clone &&
75 git submodule update --init -- sub1 sub3 &&
f030c96d
ÆAB
76 git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" > ../actual &&
77 git config foo.bar zar &&
78 git submodule foreach "git config --file \"\$toplevel/.git/config\" foo.bar"
d69ecf6f
JH
79 ) &&
80 test_cmp expect actual
81'
82
15fc56a8
JH
83test_expect_success 'setup nested submodules' '
84 git clone submodule nested1 &&
85 git clone submodule nested2 &&
86 git clone submodule nested3 &&
87 (
88 cd nested3 &&
89 git submodule add ../submodule submodule &&
90 test_tick &&
91 git commit -m "submodule" &&
92 git submodule init submodule
93 ) &&
94 (
95 cd nested2 &&
96 git submodule add ../nested3 nested3 &&
97 test_tick &&
98 git commit -m "nested3" &&
99 git submodule init nested3
100 ) &&
101 (
102 cd nested1 &&
103 git submodule add ../nested2 nested2 &&
104 test_tick &&
105 git commit -m "nested2" &&
106 git submodule init nested2
107 ) &&
108 (
109 cd super &&
110 git submodule add ../nested1 nested1 &&
111 test_tick &&
112 git commit -m "nested1" &&
113 git submodule init nested1
114 )
115'
116
117test_expect_success 'use "submodule foreach" to checkout 2nd level submodule' '
118 git clone super clone2 &&
119 (
120 cd clone2 &&
121 test ! -d sub1/.git &&
122 test ! -d sub2/.git &&
123 test ! -d sub3/.git &&
124 test ! -d nested1/.git &&
125 git submodule update --init &&
126 test -d sub1/.git &&
127 test -d sub2/.git &&
128 test -d sub3/.git &&
129 test -d nested1/.git &&
130 test ! -d nested1/nested2/.git &&
131 git submodule foreach "git submodule update --init" &&
132 test -d nested1/nested2/.git &&
133 test ! -d nested1/nested2/nested3/.git
134 )
135'
136
137test_expect_success 'use "foreach --recursive" to checkout all submodules' '
138 (
139 cd clone2 &&
140 git submodule foreach --recursive "git submodule update --init" &&
141 test -d nested1/nested2/nested3/.git &&
142 test -d nested1/nested2/nested3/submodule/.git
143 )
144'
145
146cat > expect <<EOF
147Entering 'nested1'
148Entering 'nested1/nested2'
149Entering 'nested1/nested2/nested3'
150Entering 'nested1/nested2/nested3/submodule'
151Entering 'sub1'
152Entering 'sub2'
153Entering 'sub3'
154EOF
155
156test_expect_success 'test messages from "foreach --recursive"' '
157 (
158 cd clone2 &&
159 git submodule foreach --recursive "true" > ../actual
160 ) &&
161 test_cmp expect actual
162'
163
164cat > expect <<EOF
165nested1-nested1
166nested2-nested2
167nested3-nested3
168submodule-submodule
169foo1-sub1
170foo2-sub2
171foo3-sub3
172EOF
173
174test_expect_success 'test "foreach --quiet --recursive"' '
175 (
176 cd clone2 &&
177 git submodule foreach -q --recursive "echo \$name-\$path" > ../actual
178 ) &&
179 test_cmp expect actual
180'
181
b13fd5c1
JH
182test_expect_success 'use "update --recursive" to checkout all submodules' '
183 git clone super clone3 &&
184 (
185 cd clone3 &&
186 test ! -d sub1/.git &&
187 test ! -d sub2/.git &&
188 test ! -d sub3/.git &&
189 test ! -d nested1/.git &&
190 git submodule update --init --recursive &&
191 test -d sub1/.git &&
192 test -d sub2/.git &&
193 test -d sub3/.git &&
194 test -d nested1/.git &&
195 test -d nested1/nested2/.git &&
196 test -d nested1/nested2/nested3/.git &&
197 test -d nested1/nested2/nested3/submodule/.git
198 )
199'
200
64b19ffe
JH
201nested1sha1=$(cd clone3/nested1 && git rev-parse HEAD)
202nested2sha1=$(cd clone3/nested1/nested2 && git rev-parse HEAD)
203nested3sha1=$(cd clone3/nested1/nested2/nested3 && git rev-parse HEAD)
204submodulesha1=$(cd clone3/nested1/nested2/nested3/submodule && git rev-parse HEAD)
205sub1sha1=$(cd clone3/sub1 && git rev-parse HEAD)
206sub2sha1=$(cd clone3/sub2 && git rev-parse HEAD)
207sub3sha1=$(cd clone3/sub3 && git rev-parse HEAD)
e3ae4a86
JH
208sub1sha1_short=$(cd clone3/sub1 && git rev-parse --short HEAD)
209sub2sha1_short=$(cd clone3/sub2 && git rev-parse --short HEAD)
64b19ffe
JH
210
211cat > expect <<EOF
212 $nested1sha1 nested1 (heads/master)
213 $nested2sha1 nested1/nested2 (heads/master)
214 $nested3sha1 nested1/nested2/nested3 (heads/master)
215 $submodulesha1 nested1/nested2/nested3/submodule (heads/master)
e3ae4a86
JH
216 $sub1sha1 sub1 ($sub1sha1_short)
217 $sub2sha1 sub2 ($sub2sha1_short)
64b19ffe
JH
218 $sub3sha1 sub3 (heads/master)
219EOF
220
221test_expect_success 'test "status --recursive"' '
222 (
223 cd clone3 &&
224 git submodule status --recursive > ../actual
225 ) &&
226 test_cmp expect actual
227'
228
98dbe63d
KB
229sed -e "/nested1 /s/.*/+$nested1sha1 nested1 (file2~1)/;/sub[1-3]/d" < expect > expect2
230mv -f expect2 expect
231
232test_expect_success 'ensure "status --cached --recursive" preserves the --cached flag' '
233 (
234 cd clone3 &&
235 (
236 cd nested1 &&
237 test_commit file2
238 ) &&
239 git submodule status --cached --recursive -- nested1 > ../actual
240 ) &&
241 test_cmp expect actual
242'
243
e7fed18a
JH
244test_expect_success 'use "git clone --recursive" to checkout all submodules' '
245 git clone --recursive super clone4 &&
246 test -d clone4/.git &&
247 test -d clone4/sub1/.git &&
248 test -d clone4/sub2/.git &&
249 test -d clone4/sub3/.git &&
250 test -d clone4/nested1/.git &&
251 test -d clone4/nested1/nested2/.git &&
252 test -d clone4/nested1/nested2/nested3/.git &&
253 test -d clone4/nested1/nested2/nested3/submodule/.git
254'
255
a7eff1a8
KB
256test_expect_success 'test "update --recursive" with a flag with spaces' '
257 git clone super "common objects" &&
258 git clone super clone5 &&
259 (
260 cd clone5 &&
261 test ! -d nested1/.git &&
262 git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" &&
263 test -d nested1/.git &&
264 test -d nested1/nested2/.git &&
265 test -d nested1/nested2/nested3/.git &&
266 test -f nested1/.git/objects/info/alternates &&
267 test -f nested1/nested2/.git/objects/info/alternates &&
268 test -f nested1/nested2/nested3/.git/objects/info/alternates
269 )
270'
271
98dbe63d
KB
272test_expect_success 'use "update --recursive nested1" to checkout all submodules rooted in nested1' '
273 git clone super clone6 &&
274 (
275 cd clone6 &&
276 test ! -d sub1/.git &&
277 test ! -d sub2/.git &&
278 test ! -d sub3/.git &&
279 test ! -d nested1/.git &&
280 git submodule update --init --recursive -- nested1 &&
281 test ! -d sub1/.git &&
282 test ! -d sub2/.git &&
283 test ! -d sub3/.git &&
284 test -d nested1/.git &&
285 test -d nested1/nested2/.git &&
286 test -d nested1/nested2/nested3/.git &&
287 test -d nested1/nested2/nested3/submodule/.git
288 )
289'
290
d69ecf6f 291test_done