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 test_expect_success
'setup a submodule tree' '
19 git commit -m upstream
21 git clone super submodule &&
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 &&
35 git commit -m "submodules" &&
36 git submodule init sub1 &&
37 git submodule init sub2 &&
38 git submodule init sub3
42 echo different > file &&
45 git commit -m "different"
55 git commit -m "update sub3"
59 sub1sha1
=$
(cd super
/sub1
&& git rev-parse HEAD
)
60 sub3sha1
=$
(cd super
/sub3
&& git rev-parse HEAD
)
69 test_expect_success
'test basic "submodule foreach" usage' '
70 git clone super clone &&
73 git submodule update --init -- sub1 sub3 &&
74 git submodule foreach "echo \$name-\$path-\$sha1" > ../actual
76 test_cmp expect actual
79 test_expect_success
'setup nested submodules' '
80 git clone submodule nested1 &&
81 git clone submodule nested2 &&
82 git clone submodule nested3 &&
85 git submodule add ../submodule submodule &&
87 git commit -m "submodule" &&
88 git submodule init submodule
92 git submodule add ../nested3 nested3 &&
94 git commit -m "nested3" &&
95 git submodule init nested3
99 git submodule add ../nested2 nested2 &&
101 git commit -m "nested2" &&
102 git submodule init nested2
106 git submodule add ../nested1 nested1 &&
108 git commit -m "nested1" &&
109 git submodule init nested1
113 test_expect_success
'use "submodule foreach" to checkout 2nd level submodule' '
114 git clone super clone2 &&
117 test ! -d sub1/.git &&
118 test ! -d sub2/.git &&
119 test ! -d sub3/.git &&
120 test ! -d nested1/.git &&
121 git submodule update --init &&
125 test -d nested1/.git &&
126 test ! -d nested1/nested2/.git &&
127 git submodule foreach "git submodule update --init" &&
128 test -d nested1/nested2/.git &&
129 test ! -d nested1/nested2/nested3/.git
133 test_expect_success
'use "foreach --recursive" to checkout all submodules' '
136 git submodule foreach --recursive "git submodule update --init" &&
137 test -d nested1/nested2/nested3/.git &&
138 test -d nested1/nested2/nested3/submodule/.git
144 Entering 'nested1/nested2'
145 Entering 'nested1/nested2/nested3'
146 Entering 'nested1/nested2/nested3/submodule'
152 test_expect_success
'test messages from "foreach --recursive"' '
155 git submodule foreach --recursive "true" > ../actual
157 test_cmp expect actual
170 test_expect_success
'test "foreach --quiet --recursive"' '
173 git submodule foreach -q --recursive "echo \$name-\$path" > ../actual
175 test_cmp expect actual