config.c: trivial fix for compile-time warning
[git/dscho.git] / t / t7407-submodule-foreach.sh
blob761337ebd9030d4adbf63d2ff2eabf37fbce12cf
1 #!/bin/sh
3 # Copyright (c) 2009 Johan Herland
6 test_description='Test "git submodule foreach"
8 This test verifies that "git submodule foreach" correctly visits all submodules
9 that are currently checked out.
12 . ./test-lib.sh
15 test_expect_success 'setup a submodule tree' '
16 echo file > file &&
17 git add file &&
18 test_tick &&
19 git commit -m upstream &&
20 git clone . super &&
21 git clone super submodule &&
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 &&
33 git add .gitmodules &&
34 test_tick &&
35 git commit -m "submodules" &&
36 git submodule init sub1 &&
37 git submodule init sub2 &&
38 git submodule init sub3
39 ) &&
41 cd submodule &&
42 echo different > file &&
43 git add file &&
44 test_tick &&
45 git commit -m "different"
46 ) &&
48 cd super &&
50 cd sub3 &&
51 git pull
52 ) &&
53 git add sub3 &&
54 test_tick &&
55 git commit -m "update sub3"
59 sub1sha1=$(cd super/sub1 && git rev-parse HEAD)
60 sub3sha1=$(cd super/sub3 && git rev-parse HEAD)
62 pwd=$(pwd)
64 cat > expect <<EOF
65 Entering 'sub1'
66 $pwd/clone-foo1-sub1-$sub1sha1
67 Entering 'sub3'
68 $pwd/clone-foo3-sub3-$sub3sha1
69 EOF
71 test_expect_success 'test basic "submodule foreach" usage' '
72 git clone super clone &&
74 cd clone &&
75 git submodule update --init -- sub1 sub3 &&
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"
79 ) &&
80 test_i18ncmp expect actual
83 test_expect_success 'setup nested submodules' '
84 git clone submodule nested1 &&
85 git clone submodule nested2 &&
86 git clone submodule nested3 &&
88 cd nested3 &&
89 git submodule add ../submodule submodule &&
90 test_tick &&
91 git commit -m "submodule" &&
92 git submodule init submodule
93 ) &&
95 cd nested2 &&
96 git submodule add ../nested3 nested3 &&
97 test_tick &&
98 git commit -m "nested3" &&
99 git submodule init nested3
100 ) &&
102 cd nested1 &&
103 git submodule add ../nested2 nested2 &&
104 test_tick &&
105 git commit -m "nested2" &&
106 git submodule init nested2
107 ) &&
109 cd super &&
110 git submodule add ../nested1 nested1 &&
111 test_tick &&
112 git commit -m "nested1" &&
113 git submodule init nested1
117 test_expect_success 'use "submodule foreach" to checkout 2nd level submodule' '
118 git clone super clone2 &&
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
137 test_expect_success 'use "foreach --recursive" to checkout all submodules' '
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
146 cat > expect <<EOF
147 Entering 'nested1'
148 Entering 'nested1/nested2'
149 Entering 'nested1/nested2/nested3'
150 Entering 'nested1/nested2/nested3/submodule'
151 Entering 'sub1'
152 Entering 'sub2'
153 Entering 'sub3'
156 test_expect_success 'test messages from "foreach --recursive"' '
158 cd clone2 &&
159 git submodule foreach --recursive "true" > ../actual
160 ) &&
161 test_i18ncmp expect actual
164 cat > expect <<EOF
165 nested1-nested1
166 nested2-nested2
167 nested3-nested3
168 submodule-submodule
169 foo1-sub1
170 foo2-sub2
171 foo3-sub3
174 test_expect_success 'test "foreach --quiet --recursive"' '
176 cd clone2 &&
177 git submodule foreach -q --recursive "echo \$name-\$path" > ../actual
178 ) &&
179 if test_have_prereq MINGW
180 then
181 dos2unix actual
182 fi &&
183 test_cmp expect actual
186 test_expect_success 'use "update --recursive" to checkout all submodules' '
187 git clone super clone3 &&
189 cd clone3 &&
190 test ! -d sub1/.git &&
191 test ! -d sub2/.git &&
192 test ! -d sub3/.git &&
193 test ! -d nested1/.git &&
194 git submodule update --init --recursive &&
195 test -d sub1/.git &&
196 test -d sub2/.git &&
197 test -d sub3/.git &&
198 test -d nested1/.git &&
199 test -d nested1/nested2/.git &&
200 test -d nested1/nested2/nested3/.git &&
201 test -d nested1/nested2/nested3/submodule/.git
205 nested1sha1=$(cd clone3/nested1 && git rev-parse HEAD)
206 nested2sha1=$(cd clone3/nested1/nested2 && git rev-parse HEAD)
207 nested3sha1=$(cd clone3/nested1/nested2/nested3 && git rev-parse HEAD)
208 submodulesha1=$(cd clone3/nested1/nested2/nested3/submodule && git rev-parse HEAD)
209 sub1sha1=$(cd clone3/sub1 && git rev-parse HEAD)
210 sub2sha1=$(cd clone3/sub2 && git rev-parse HEAD)
211 sub3sha1=$(cd clone3/sub3 && git rev-parse HEAD)
212 sub1sha1_short=$(cd clone3/sub1 && git rev-parse --short HEAD)
213 sub2sha1_short=$(cd clone3/sub2 && git rev-parse --short HEAD)
215 cat > expect <<EOF
216 $nested1sha1 nested1 (heads/master)
217 $nested2sha1 nested1/nested2 (heads/master)
218 $nested3sha1 nested1/nested2/nested3 (heads/master)
219 $submodulesha1 nested1/nested2/nested3/submodule (heads/master)
220 $sub1sha1 sub1 ($sub1sha1_short)
221 $sub2sha1 sub2 ($sub2sha1_short)
222 $sub3sha1 sub3 (heads/master)
225 test_expect_success 'test "status --recursive"' '
227 cd clone3 &&
228 git submodule status --recursive > ../actual
229 ) &&
230 if test_have_prereq MINGW
231 then
232 dos2unix actual
233 fi &&
234 test_cmp expect actual
237 sed -e "/nested1 /s/.*/+$nested1sha1 nested1 (file2~1)/;/sub[1-3]/d" < expect > expect2
238 mv -f expect2 expect
240 test_expect_success 'ensure "status --cached --recursive" preserves the --cached flag' '
242 cd clone3 &&
244 cd nested1 &&
245 test_commit file2
246 ) &&
247 git submodule status --cached --recursive -- nested1 > ../actual
248 ) &&
249 if test_have_prereq MINGW
250 then
251 dos2unix actual
252 fi &&
253 test_cmp expect actual
256 test_expect_success 'use "git clone --recursive" to checkout all submodules' '
257 git clone --recursive super clone4 &&
258 test -d clone4/.git &&
259 test -d clone4/sub1/.git &&
260 test -d clone4/sub2/.git &&
261 test -d clone4/sub3/.git &&
262 test -d clone4/nested1/.git &&
263 test -d clone4/nested1/nested2/.git &&
264 test -d clone4/nested1/nested2/nested3/.git &&
265 test -d clone4/nested1/nested2/nested3/submodule/.git
268 test_expect_success 'test "update --recursive" with a flag with spaces' '
269 git clone super "common objects" &&
270 git clone super clone5 &&
272 cd clone5 &&
273 test ! -d nested1/.git &&
274 git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" &&
275 test -d nested1/.git &&
276 test -d nested1/nested2/.git &&
277 test -d nested1/nested2/nested3/.git &&
278 test -f nested1/.git/objects/info/alternates &&
279 test -f nested1/nested2/.git/objects/info/alternates &&
280 test -f nested1/nested2/nested3/.git/objects/info/alternates
284 test_expect_success 'use "update --recursive nested1" to checkout all submodules rooted in nested1' '
285 git clone super clone6 &&
287 cd clone6 &&
288 test ! -d sub1/.git &&
289 test ! -d sub2/.git &&
290 test ! -d sub3/.git &&
291 test ! -d nested1/.git &&
292 git submodule update --init --recursive -- nested1 &&
293 test ! -d sub1/.git &&
294 test ! -d sub2/.git &&
295 test ! -d sub3/.git &&
296 test -d nested1/.git &&
297 test -d nested1/nested2/.git &&
298 test -d nested1/nested2/nested3/.git &&
299 test -d nested1/nested2/nested3/submodule/.git
303 test_done