t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t7411-submodule-config.sh
blobaf0de496e07470df03e9dada0247daf8d53850f0
1 #!/bin/sh
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.
12 TEST_NO_CREATE_REPO=1
13 TEST_PASSES_SANITIZE_LEAK=true
14 . ./test-lib.sh
16 test_expect_success 'setup' '
17 git config --global protocol.file.allow always
19 test_expect_success 'submodule config cache setup' '
20 mkdir submodule &&
21 (cd submodule &&
22 git init &&
23 echo a >a &&
24 git add . &&
25 git commit -ma
26 ) &&
27 mkdir super &&
28 (cd super &&
29 git init &&
30 git submodule add ../submodule &&
31 git submodule add ../submodule a &&
32 git commit -m "add as submodule and as a" &&
33 git mv a b &&
34 git commit -m "move a to b"
38 test_expect_success 'configuration parsing with error' '
39 test_when_finished "rm -rf repo" &&
40 test_create_repo repo &&
41 cat >repo/.gitmodules <<-\EOF &&
42 [submodule "s"]
43 path
44 ignore
45 EOF
47 cd repo &&
48 test_must_fail test-tool submodule-config "" s 2>actual &&
49 test_grep "bad config" actual
53 cat >super/expect <<EOF
54 Submodule name: 'a' for path 'a'
55 Submodule name: 'a' for path 'b'
56 Submodule name: 'submodule' for path 'submodule'
57 Submodule name: 'submodule' for path 'submodule'
58 EOF
60 test_expect_success 'test parsing and lookup of submodule config by path' '
61 (cd super &&
62 test-tool submodule-config \
63 HEAD^ a \
64 HEAD b \
65 HEAD^ submodule \
66 HEAD submodule \
67 >actual &&
68 test_cmp expect actual
72 test_expect_success 'test parsing and lookup of submodule config by name' '
73 (cd super &&
74 test-tool submodule-config --name \
75 HEAD^ a \
76 HEAD a \
77 HEAD^ submodule \
78 HEAD submodule \
79 >actual &&
80 test_cmp expect actual
84 cat >super/expect_error <<EOF
85 Submodule name: 'a' for path 'b'
86 Submodule name: 'submodule' for path 'submodule'
87 EOF
89 test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' '
90 ORIG=$(git -C super rev-parse HEAD) &&
91 test_when_finished "git -C super reset --hard $ORIG" &&
92 (cd super &&
93 cp .gitmodules .gitmodules.bak &&
94 echo " value = \"" >>.gitmodules &&
95 git add .gitmodules &&
96 mv .gitmodules.bak .gitmodules &&
97 git commit -m "add error" &&
98 sha1=$(git rev-parse HEAD) &&
99 test-tool submodule-config \
100 HEAD b \
101 HEAD submodule \
102 >actual \
103 2>actual_stderr &&
104 test_cmp expect_error actual &&
105 test_grep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
109 test_expect_success 'using different treeishs works' '
111 cd super &&
112 git tag new_tag &&
113 tree=$(git rev-parse HEAD^{tree}) &&
114 commit=$(git rev-parse HEAD^{commit}) &&
115 test-tool submodule-config $commit b >expect &&
116 test-tool submodule-config $tree b >actual.1 &&
117 test-tool submodule-config new_tag b >actual.2 &&
118 test_cmp expect actual.1 &&
119 test_cmp expect actual.2
123 test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
124 ORIG=$(git -C super rev-parse HEAD) &&
125 test_when_finished "git -C super reset --hard $ORIG" &&
126 (cd super &&
127 git config -f .gitmodules \
128 submodule.submodule.fetchrecursesubmodules blabla &&
129 git add .gitmodules &&
130 git config --unset -f .gitmodules \
131 submodule.submodule.fetchrecursesubmodules &&
132 git commit -m "add error in fetchrecursesubmodules" &&
133 test-tool submodule-config \
134 HEAD b \
135 HEAD submodule \
136 >actual &&
137 test_cmp expect_error actual
141 test_expect_success 'reading submodules config from the working tree' '
142 (cd super &&
143 echo "../submodule" >expect &&
144 test-tool submodule config-list submodule.submodule.url >actual &&
145 test_cmp expect actual
149 test_expect_success 'unsetting submodules config from the working tree' '
150 (cd super &&
151 test-tool submodule config-unset submodule.submodule.url &&
152 test-tool submodule config-list submodule.submodule.url >actual &&
153 test_must_be_empty actual
158 test_expect_success 'writing submodules config' '
159 (cd super &&
160 echo "new_url" >expect &&
161 test-tool submodule config-set submodule.submodule.url "new_url" &&
162 test-tool submodule config-list submodule.submodule.url >actual &&
163 test_cmp expect actual
167 test_expect_success 'overwriting unstaged submodules config' '
168 test_when_finished "git -C super checkout .gitmodules" &&
169 (cd super &&
170 echo "newer_url" >expect &&
171 test-tool submodule config-set submodule.submodule.url "newer_url" &&
172 test-tool submodule config-list submodule.submodule.url >actual &&
173 test_cmp expect actual
177 test_expect_success 'writeable .gitmodules when it is in the working tree' '
178 test-tool -C super submodule config-writeable
181 test_expect_success 'writeable .gitmodules when it is nowhere in the repository' '
182 ORIG=$(git -C super rev-parse HEAD) &&
183 test_when_finished "git -C super reset --hard $ORIG" &&
184 (cd super &&
185 git rm .gitmodules &&
186 git commit -m "remove .gitmodules from the current branch" &&
187 test-tool submodule config-writeable
191 test_expect_success 'non-writeable .gitmodules when it is in the index but not in the working tree' '
192 test_when_finished "git -C super checkout .gitmodules" &&
193 (cd super &&
194 rm -f .gitmodules &&
195 test_must_fail test-tool submodule config-writeable
199 test_expect_success 'non-writeable .gitmodules when it is in the current branch but not in the index' '
200 ORIG=$(git -C super rev-parse HEAD) &&
201 test_when_finished "git -C super reset --hard $ORIG" &&
202 (cd super &&
203 git rm .gitmodules &&
204 test_must_fail test-tool submodule config-writeable
208 test_expect_success 'reading submodules config from the index when .gitmodules is not in the working tree' '
209 ORIG=$(git -C super rev-parse HEAD) &&
210 test_when_finished "git -C super reset --hard $ORIG" &&
211 (cd super &&
212 test-tool submodule config-set submodule.submodule.url "staged_url" &&
213 git add .gitmodules &&
214 rm -f .gitmodules &&
215 echo "staged_url" >expect &&
216 test-tool submodule config-list submodule.submodule.url >actual &&
217 test_cmp expect actual
221 test_expect_success 'reading submodules config from the current branch when .gitmodules is not in the index' '
222 ORIG=$(git -C super rev-parse HEAD) &&
223 test_when_finished "git -C super reset --hard $ORIG" &&
224 (cd super &&
225 git rm .gitmodules &&
226 echo "../submodule" >expect &&
227 test-tool submodule config-list submodule.submodule.url >actual &&
228 test_cmp expect actual
232 test_expect_success 'reading nested submodules config' '
233 (cd super &&
234 git init submodule/nested_submodule &&
235 echo "a" >submodule/nested_submodule/a &&
236 git -C submodule/nested_submodule add a &&
237 git -C submodule/nested_submodule commit -m "add a" &&
238 git -C submodule submodule add ./nested_submodule &&
239 git -C submodule add nested_submodule &&
240 git -C submodule commit -m "added nested_submodule" &&
241 git add submodule &&
242 git commit -m "updated submodule" &&
243 echo "./nested_submodule" >expect &&
244 test-tool submodule-nested-repo-config \
245 submodule submodule.nested_submodule.url >actual &&
246 test_cmp expect actual
250 test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' '
251 test_when_finished "git -C super/submodule checkout .gitmodules" &&
252 (cd super &&
253 echo "./nested_submodule" >expect &&
254 rm submodule/.gitmodules &&
255 test-tool submodule-nested-repo-config \
256 submodule submodule.nested_submodule.url >actual 2>warning &&
257 test_must_be_empty warning &&
258 test_cmp expect actual
262 test_done