debian: new upstream point release
[git/debian.git] / t / t7411-submodule-config.sh
blob31271f8e0a61f7b071c770f9efad0e235920f37f
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-lib.sh
15 test_expect_success 'setup' '
16 git config --global protocol.file.allow always
18 test_expect_success 'submodule config cache setup' '
19 mkdir submodule &&
20 (cd submodule &&
21 git init &&
22 echo a >a &&
23 git add . &&
24 git commit -ma
25 ) &&
26 mkdir super &&
27 (cd super &&
28 git init &&
29 git submodule add ../submodule &&
30 git submodule add ../submodule a &&
31 git commit -m "add as submodule and as a" &&
32 git mv a b &&
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 &&
41 [submodule "s"]
42 path
43 ignore
44 EOF
46 cd repo &&
47 test_must_fail test-tool submodule-config "" s 2>actual &&
48 test_grep "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'
57 EOF
59 test_expect_success 'test parsing and lookup of submodule config by path' '
60 (cd super &&
61 test-tool submodule-config \
62 HEAD^ a \
63 HEAD b \
64 HEAD^ submodule \
65 HEAD submodule \
66 >actual &&
67 test_cmp expect actual
71 test_expect_success 'test parsing and lookup of submodule config by name' '
72 (cd super &&
73 test-tool submodule-config --name \
74 HEAD^ a \
75 HEAD a \
76 HEAD^ submodule \
77 HEAD submodule \
78 >actual &&
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'
86 EOF
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" &&
91 (cd super &&
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 \
99 HEAD b \
100 HEAD submodule \
101 >actual \
102 2>actual_stderr &&
103 test_cmp expect_error actual &&
104 test_grep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
108 test_expect_success 'using different treeishs works' '
110 cd super &&
111 git tag new_tag &&
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" &&
125 (cd super &&
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 \
133 HEAD b \
134 HEAD submodule \
135 >actual &&
136 test_cmp expect_error actual
140 test_expect_success 'reading submodules config from the working tree' '
141 (cd super &&
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' '
149 (cd super &&
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' '
158 (cd super &&
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" &&
168 (cd super &&
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" &&
183 (cd super &&
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" &&
192 (cd super &&
193 rm -f .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" &&
201 (cd super &&
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" &&
210 (cd super &&
211 test-tool submodule config-set submodule.submodule.url "staged_url" &&
212 git add .gitmodules &&
213 rm -f .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" &&
223 (cd super &&
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' '
232 (cd super &&
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" &&
240 git add 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" &&
251 (cd super &&
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
261 test_done