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.
15 *MINGW
*) GIT_TEST_CMP
="diff -uw";;
19 test_expect_success
'setup a submodule tree' '
23 git commit -m upstream &&
25 git clone super submodule &&
28 git submodule add ../submodule sub1 &&
29 git submodule add ../submodule sub2 &&
30 git submodule add ../submodule sub3 &&
31 git config -f .gitmodules --rename-section \
32 submodule.sub1 submodule.foo1 &&
33 git config -f .gitmodules --rename-section \
34 submodule.sub2 submodule.foo2 &&
35 git config -f .gitmodules --rename-section \
36 submodule.sub3 submodule.foo3 &&
37 git add .gitmodules &&
39 git commit -m "submodules" &&
40 git submodule init sub1 &&
41 git submodule init sub2 &&
42 git submodule init sub3
46 echo different > file &&
49 git commit -m "different"
59 git commit -m "update sub3"
63 sub1sha1
=$
(cd super
/sub1
&& git rev-parse HEAD
)
64 sub3sha1
=$
(cd super
/sub3
&& git rev-parse HEAD
)
70 $pwd/clone-foo1-sub1-$sub1sha1
72 $pwd/clone-foo3-sub3-$sub3sha1
75 test_expect_success
'test basic "submodule foreach" usage' '
76 git clone super clone &&
79 git submodule update --init -- sub1 sub3 &&
80 git submodule foreach "echo \$toplevel-\$name-\$path-\$sha1" > ../actual &&
81 git config foo.bar zar &&
82 git submodule foreach "git config --file \"\$toplevel/.git/config\" foo.bar"
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 &&
93 git submodule add ../submodule submodule &&
95 git commit -m "submodule" &&
96 git submodule init submodule
100 git submodule add ../nested3 nested3 &&
102 git commit -m "nested3" &&
103 git submodule init nested3
107 git submodule add ../nested2 nested2 &&
109 git commit -m "nested2" &&
110 git submodule init nested2
114 git submodule add ../nested1 nested1 &&
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 &&
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 &&
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' '
144 git submodule foreach --recursive "git submodule update --init" &&
145 test -d nested1/nested2/nested3/.git &&
146 test -d nested1/nested2/nested3/submodule/.git
152 Entering 'nested1/nested2'
153 Entering 'nested1/nested2/nested3'
154 Entering 'nested1/nested2/nested3/submodule'
160 test_expect_success
'test messages from "foreach --recursive"' '
163 git submodule foreach --recursive "true" > ../actual
165 test_cmp expect actual
178 test_expect_success
'test "foreach --quiet --recursive"' '
181 git submodule foreach -q --recursive "echo \$name-\$path" > ../actual
183 test_cmp expect actual
186 test_expect_success
'use "update --recursive" to checkout all submodules' '
187 git clone super 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 &&
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 clone
3/nested1
&& git rev-parse HEAD
)
206 nested2sha1
=$
(cd clone
3/nested
1/nested2
&& git rev-parse HEAD
)
207 nested3sha1
=$
(cd clone
3/nested
1/nested
2/nested3
&& git rev-parse HEAD
)
208 submodulesha1
=$
(cd clone
3/nested
1/nested
2/nested
3/submodule
&& git rev-parse HEAD
)
209 sub1sha1
=$
(cd clone
3/sub1
&& git rev-parse HEAD
)
210 sub2sha1
=$
(cd clone
3/sub2
&& git rev-parse HEAD
)
211 sub3sha1
=$
(cd clone
3/sub3
&& git rev-parse HEAD
)
212 sub1sha1_short
=$
(cd clone
3/sub1
&& git rev-parse
--short HEAD
)
213 sub2sha1_short
=$
(cd clone
3/sub2
&& git rev-parse
--short HEAD
)
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"' '
228 git submodule status --recursive > ../actual
230 test_cmp expect actual
233 test_expect_success
'use "git clone --recursive" to checkout all submodules' '
234 git clone --recursive super clone4 &&
235 test -d clone4/.git &&
236 test -d clone4/sub1/.git &&
237 test -d clone4/sub2/.git &&
238 test -d clone4/sub3/.git &&
239 test -d clone4/nested1/.git &&
240 test -d clone4/nested1/nested2/.git &&
241 test -d clone4/nested1/nested2/nested3/.git &&
242 test -d clone4/nested1/nested2/nested3/submodule/.git