3 # Copyright (c) 2014 Heiko Voigt
6 test_description
='Test submodules config cache infrastructure
8 This test verifies that parsing .gitmodules configurations directly
9 from the database and from the worktree works.
15 test_expect_success
'setup' '
16 git config --global protocol.file.allow always
18 test_expect_success
'submodule config cache setup' '
29 git submodule add ../submodule &&
30 git submodule add ../submodule a &&
31 git commit -m "add as submodule and as a" &&
33 git commit -m "move a to b"
37 test_expect_success
'configuration parsing with error' '
38 test_when_finished "rm -rf repo" &&
39 test_create_repo repo &&
40 cat >repo/.gitmodules <<-\EOF &&
47 test_must_fail test-tool submodule-config "" s 2>actual &&
48 test_i18ngrep "bad config" actual
52 cat >super
/expect
<<EOF
53 Submodule name: 'a' for path 'a'
54 Submodule name: 'a' for path 'b'
55 Submodule name: 'submodule' for path 'submodule'
56 Submodule name: 'submodule' for path 'submodule'
59 test_expect_success
'test parsing and lookup of submodule config by path' '
61 test-tool submodule-config \
67 test_cmp expect actual
71 test_expect_success
'test parsing and lookup of submodule config by name' '
73 test-tool submodule-config --name \
79 test_cmp expect actual
83 cat >super
/expect_error
<<EOF
84 Submodule name: 'a' for path 'b'
85 Submodule name: 'submodule' for path 'submodule'
88 test_expect_success
'error in history of one submodule config lets continue, stderr message contains blob ref' '
89 ORIG=$(git -C super rev-parse HEAD) &&
90 test_when_finished "git -C super reset --hard $ORIG" &&
92 cp .gitmodules .gitmodules.bak &&
93 echo " value = \"" >>.gitmodules &&
94 git add .gitmodules &&
95 mv .gitmodules.bak .gitmodules &&
96 git commit -m "add error" &&
97 sha1=$(git rev-parse HEAD) &&
98 test-tool submodule-config \
103 test_cmp expect_error actual &&
104 test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
108 test_expect_success
'using different treeishs works' '
112 tree=$(git rev-parse HEAD^{tree}) &&
113 commit=$(git rev-parse HEAD^{commit}) &&
114 test-tool submodule-config $commit b >expect &&
115 test-tool submodule-config $tree b >actual.1 &&
116 test-tool submodule-config new_tag b >actual.2 &&
117 test_cmp expect actual.1 &&
118 test_cmp expect actual.2
122 test_expect_success
'error in history in fetchrecursesubmodule lets continue' '
123 ORIG=$(git -C super rev-parse HEAD) &&
124 test_when_finished "git -C super reset --hard $ORIG" &&
126 git config -f .gitmodules \
127 submodule.submodule.fetchrecursesubmodules blabla &&
128 git add .gitmodules &&
129 git config --unset -f .gitmodules \
130 submodule.submodule.fetchrecursesubmodules &&
131 git commit -m "add error in fetchrecursesubmodules" &&
132 test-tool submodule-config \
136 test_cmp expect_error actual
140 test_expect_success
'reading submodules config from the working tree' '
142 echo "../submodule" >expect &&
143 test-tool submodule config-list submodule.submodule.url >actual &&
144 test_cmp expect actual
148 test_expect_success
'unsetting submodules config from the working tree' '
150 test-tool submodule config-unset submodule.submodule.url &&
151 test-tool submodule config-list submodule.submodule.url >actual &&
152 test_must_be_empty actual
157 test_expect_success
'writing submodules config' '
159 echo "new_url" >expect &&
160 test-tool submodule config-set submodule.submodule.url "new_url" &&
161 test-tool submodule config-list submodule.submodule.url >actual &&
162 test_cmp expect actual
166 test_expect_success
'overwriting unstaged submodules config' '
167 test_when_finished "git -C super checkout .gitmodules" &&
169 echo "newer_url" >expect &&
170 test-tool submodule config-set submodule.submodule.url "newer_url" &&
171 test-tool submodule config-list submodule.submodule.url >actual &&
172 test_cmp expect actual
176 test_expect_success
'writeable .gitmodules when it is in the working tree' '
177 test-tool -C super submodule config-writeable
180 test_expect_success
'writeable .gitmodules when it is nowhere in the repository' '
181 ORIG=$(git -C super rev-parse HEAD) &&
182 test_when_finished "git -C super reset --hard $ORIG" &&
184 git rm .gitmodules &&
185 git commit -m "remove .gitmodules from the current branch" &&
186 test-tool submodule config-writeable
190 test_expect_success
'non-writeable .gitmodules when it is in the index but not in the working tree' '
191 test_when_finished "git -C super checkout .gitmodules" &&
194 test_must_fail test-tool submodule config-writeable
198 test_expect_success
'non-writeable .gitmodules when it is in the current branch but not in the index' '
199 ORIG=$(git -C super rev-parse HEAD) &&
200 test_when_finished "git -C super reset --hard $ORIG" &&
202 git rm .gitmodules &&
203 test_must_fail test-tool submodule config-writeable
207 test_expect_success
'reading submodules config from the index when .gitmodules is not in the working tree' '
208 ORIG=$(git -C super rev-parse HEAD) &&
209 test_when_finished "git -C super reset --hard $ORIG" &&
211 test-tool submodule config-set submodule.submodule.url "staged_url" &&
212 git add .gitmodules &&
214 echo "staged_url" >expect &&
215 test-tool submodule config-list submodule.submodule.url >actual &&
216 test_cmp expect actual
220 test_expect_success
'reading submodules config from the current branch when .gitmodules is not in the index' '
221 ORIG=$(git -C super rev-parse HEAD) &&
222 test_when_finished "git -C super reset --hard $ORIG" &&
224 git rm .gitmodules &&
225 echo "../submodule" >expect &&
226 test-tool submodule config-list submodule.submodule.url >actual &&
227 test_cmp expect actual
231 test_expect_success
'reading nested submodules config' '
233 git init submodule/nested_submodule &&
234 echo "a" >submodule/nested_submodule/a &&
235 git -C submodule/nested_submodule add a &&
236 git -C submodule/nested_submodule commit -m "add a" &&
237 git -C submodule submodule add ./nested_submodule &&
238 git -C submodule add nested_submodule &&
239 git -C submodule commit -m "added nested_submodule" &&
241 git commit -m "updated submodule" &&
242 echo "./nested_submodule" >expect &&
243 test-tool submodule-nested-repo-config \
244 submodule submodule.nested_submodule.url >actual &&
245 test_cmp expect actual
249 test_expect_success
'reading nested submodules config when .gitmodules is not in the working tree' '
250 test_when_finished "git -C super/submodule checkout .gitmodules" &&
252 echo "./nested_submodule" >expect &&
253 rm submodule/.gitmodules &&
254 test-tool submodule-nested-repo-config \
255 submodule submodule.nested_submodule.url >actual 2>warning &&
256 test_must_be_empty warning &&
257 test_cmp expect actual