send-email: accept absolute path even on Windows
[git/dscho.git] / t / t7407-submodule-foreach.sh
blob4c847645db4998e51769fae4589df74119cd9612
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 if test_have_prereq MINGW
81 then
82 dos2unix actual
83 fi &&
84 test_cmp expect actual
87 test_expect_success 'setup nested submodules' '
88 git clone submodule nested1 &&
89 git clone submodule nested2 &&
90 git clone submodule nested3 &&
92 cd nested3 &&
93 git submodule add ../submodule submodule &&
94 test_tick &&
95 git commit -m "submodule" &&
96 git submodule init submodule
97 ) &&
99 cd nested2 &&
100 git submodule add ../nested3 nested3 &&
101 test_tick &&
102 git commit -m "nested3" &&
103 git submodule init nested3
104 ) &&
106 cd nested1 &&
107 git submodule add ../nested2 nested2 &&
108 test_tick &&
109 git commit -m "nested2" &&
110 git submodule init nested2
111 ) &&
113 cd super &&
114 git submodule add ../nested1 nested1 &&
115 test_tick &&
116 git commit -m "nested1" &&
117 git submodule init nested1
121 test_expect_success 'use "submodule foreach" to checkout 2nd level submodule' '
122 git clone super clone2 &&
124 cd clone2 &&
125 test ! -d sub1/.git &&
126 test ! -d sub2/.git &&
127 test ! -d sub3/.git &&
128 test ! -d nested1/.git &&
129 git submodule update --init &&
130 test -d sub1/.git &&
131 test -d sub2/.git &&
132 test -d sub3/.git &&
133 test -d nested1/.git &&
134 test ! -d nested1/nested2/.git &&
135 git submodule foreach "git submodule update --init" &&
136 test -d nested1/nested2/.git &&
137 test ! -d nested1/nested2/nested3/.git
141 test_expect_success 'use "foreach --recursive" to checkout all submodules' '
143 cd clone2 &&
144 git submodule foreach --recursive "git submodule update --init" &&
145 test -d nested1/nested2/nested3/.git &&
146 test -d nested1/nested2/nested3/submodule/.git
150 cat > expect <<EOF
151 Entering 'nested1'
152 Entering 'nested1/nested2'
153 Entering 'nested1/nested2/nested3'
154 Entering 'nested1/nested2/nested3/submodule'
155 Entering 'sub1'
156 Entering 'sub2'
157 Entering 'sub3'
160 test_expect_success 'test messages from "foreach --recursive"' '
162 cd clone2 &&
163 git submodule foreach --recursive "true" > ../actual
164 ) &&
165 if test_have_prereq MINGW
166 then
167 dos2unix actual
168 fi &&
169 test_cmp expect actual
172 cat > expect <<EOF
173 nested1-nested1
174 nested2-nested2
175 nested3-nested3
176 submodule-submodule
177 foo1-sub1
178 foo2-sub2
179 foo3-sub3
182 test_expect_success 'test "foreach --quiet --recursive"' '
184 cd clone2 &&
185 git submodule foreach -q --recursive "echo \$name-\$path" > ../actual
186 ) &&
187 if test_have_prereq MINGW
188 then
189 dos2unix actual
190 fi &&
191 test_cmp expect actual
194 test_expect_success 'use "update --recursive" to checkout all submodules' '
195 git clone super clone3 &&
197 cd clone3 &&
198 test ! -d sub1/.git &&
199 test ! -d sub2/.git &&
200 test ! -d sub3/.git &&
201 test ! -d nested1/.git &&
202 git submodule update --init --recursive &&
203 test -d sub1/.git &&
204 test -d sub2/.git &&
205 test -d sub3/.git &&
206 test -d nested1/.git &&
207 test -d nested1/nested2/.git &&
208 test -d nested1/nested2/nested3/.git &&
209 test -d nested1/nested2/nested3/submodule/.git
213 nested1sha1=$(cd clone3/nested1 && git rev-parse HEAD)
214 nested2sha1=$(cd clone3/nested1/nested2 && git rev-parse HEAD)
215 nested3sha1=$(cd clone3/nested1/nested2/nested3 && git rev-parse HEAD)
216 submodulesha1=$(cd clone3/nested1/nested2/nested3/submodule && git rev-parse HEAD)
217 sub1sha1=$(cd clone3/sub1 && git rev-parse HEAD)
218 sub2sha1=$(cd clone3/sub2 && git rev-parse HEAD)
219 sub3sha1=$(cd clone3/sub3 && git rev-parse HEAD)
220 sub1sha1_short=$(cd clone3/sub1 && git rev-parse --short HEAD)
221 sub2sha1_short=$(cd clone3/sub2 && git rev-parse --short HEAD)
223 cat > expect <<EOF
224 $nested1sha1 nested1 (heads/master)
225 $nested2sha1 nested1/nested2 (heads/master)
226 $nested3sha1 nested1/nested2/nested3 (heads/master)
227 $submodulesha1 nested1/nested2/nested3/submodule (heads/master)
228 $sub1sha1 sub1 ($sub1sha1_short)
229 $sub2sha1 sub2 ($sub2sha1_short)
230 $sub3sha1 sub3 (heads/master)
233 test_expect_success 'test "status --recursive"' '
235 cd clone3 &&
236 git submodule status --recursive > ../actual
237 ) &&
238 if test_have_prereq MINGW
239 then
240 dos2unix actual
241 fi &&
242 test_cmp expect actual
245 sed -e "/nested1 /s/.*/+$nested1sha1 nested1 (file2~1)/;/sub[1-3]/d" < expect > expect2
246 mv -f expect2 expect
248 test_expect_success 'ensure "status --cached --recursive" preserves the --cached flag' '
250 cd clone3 &&
252 cd nested1 &&
253 test_commit file2
254 ) &&
255 git submodule status --cached --recursive -- nested1 > ../actual
256 ) &&
257 if test_have_prereq MINGW
258 then
259 dos2unix actual
260 fi &&
261 test_cmp expect actual
264 test_expect_success 'use "git clone --recursive" to checkout all submodules' '
265 git clone --recursive super clone4 &&
266 test -d clone4/.git &&
267 test -d clone4/sub1/.git &&
268 test -d clone4/sub2/.git &&
269 test -d clone4/sub3/.git &&
270 test -d clone4/nested1/.git &&
271 test -d clone4/nested1/nested2/.git &&
272 test -d clone4/nested1/nested2/nested3/.git &&
273 test -d clone4/nested1/nested2/nested3/submodule/.git
276 test_expect_success 'test "update --recursive" with a flag with spaces' '
277 git clone super "common objects" &&
278 git clone super clone5 &&
280 cd clone5 &&
281 test ! -d nested1/.git &&
282 git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" &&
283 test -d nested1/.git &&
284 test -d nested1/nested2/.git &&
285 test -d nested1/nested2/nested3/.git &&
286 test -f nested1/.git/objects/info/alternates &&
287 test -f nested1/nested2/.git/objects/info/alternates &&
288 test -f nested1/nested2/nested3/.git/objects/info/alternates
292 test_expect_success 'use "update --recursive nested1" to checkout all submodules rooted in nested1' '
293 git clone super clone6 &&
295 cd clone6 &&
296 test ! -d sub1/.git &&
297 test ! -d sub2/.git &&
298 test ! -d sub3/.git &&
299 test ! -d nested1/.git &&
300 git submodule update --init --recursive -- nested1 &&
301 test ! -d sub1/.git &&
302 test ! -d sub2/.git &&
303 test ! -d sub3/.git &&
304 test -d nested1/.git &&
305 test -d nested1/nested2/.git &&
306 test -d nested1/nested2/nested3/.git &&
307 test -d nested1/nested2/nested3/submodule/.git
311 test_done