]>
Commit | Line | Data |
---|---|---|
959b5455 HV |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2014 Heiko Voigt | |
4 | # | |
5 | ||
6 | test_description='Test submodules config cache infrastructure | |
7 | ||
851e18c3 HV |
8 | This test verifies that parsing .gitmodules configurations directly |
9 | from the database and from the worktree works. | |
959b5455 HV |
10 | ' |
11 | ||
12 | TEST_NO_CREATE_REPO=1 | |
13 | . ./test-lib.sh | |
14 | ||
0d3beb71 TB |
15 | test_expect_success 'setup' ' |
16 | git config --global protocol.file.allow always | |
17 | ' | |
959b5455 HV |
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" | |
34 | ) | |
35 | ' | |
36 | ||
5ea50954 BW |
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 | |
45 | ( | |
46 | cd repo && | |
b6188213 | 47 | test_must_fail test-tool submodule-config "" s 2>actual && |
6789275d | 48 | test_grep "bad config" actual |
5ea50954 BW |
49 | ) |
50 | ' | |
51 | ||
959b5455 HV |
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 | |
58 | ||
59 | test_expect_success 'test parsing and lookup of submodule config by path' ' | |
60 | (cd super && | |
b6188213 | 61 | test-tool submodule-config \ |
959b5455 HV |
62 | HEAD^ a \ |
63 | HEAD b \ | |
64 | HEAD^ submodule \ | |
65 | HEAD submodule \ | |
66 | >actual && | |
67 | test_cmp expect actual | |
68 | ) | |
69 | ' | |
70 | ||
71 | test_expect_success 'test parsing and lookup of submodule config by name' ' | |
72 | (cd super && | |
b6188213 | 73 | test-tool submodule-config --name \ |
959b5455 HV |
74 | HEAD^ a \ |
75 | HEAD a \ | |
76 | HEAD^ submodule \ | |
77 | HEAD submodule \ | |
78 | >actual && | |
79 | test_cmp expect actual | |
80 | ) | |
81 | ' | |
82 | ||
83 | cat >super/expect_error <<EOF | |
84 | Submodule name: 'a' for path 'b' | |
85 | Submodule name: 'submodule' for path 'submodule' | |
86 | EOF | |
87 | ||
d1b13df5 | 88 | test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' ' |
996df4d0 AO |
89 | ORIG=$(git -C super rev-parse HEAD) && |
90 | test_when_finished "git -C super reset --hard $ORIG" && | |
959b5455 HV |
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" && | |
514dea90 | 97 | sha1=$(git rev-parse HEAD) && |
b6188213 | 98 | test-tool submodule-config \ |
514dea90 HV |
99 | HEAD b \ |
100 | HEAD submodule \ | |
d1b13df5 AO |
101 | >actual \ |
102 | 2>actual_stderr && | |
103 | test_cmp expect_error actual && | |
6789275d | 104 | test_grep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null |
514dea90 HV |
105 | ) |
106 | ' | |
107 | ||
73c293bb SB |
108 | test_expect_success 'using different treeishs works' ' |
109 | ( | |
110 | cd super && | |
111 | git tag new_tag && | |
112 | tree=$(git rev-parse HEAD^{tree}) && | |
113 | commit=$(git rev-parse HEAD^{commit}) && | |
b6188213 NTND |
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 && | |
73c293bb SB |
117 | test_cmp expect actual.1 && |
118 | test_cmp expect actual.2 | |
119 | ) | |
120 | ' | |
121 | ||
027771fc | 122 | test_expect_success 'error in history in fetchrecursesubmodule lets continue' ' |
996df4d0 AO |
123 | ORIG=$(git -C super rev-parse HEAD) && |
124 | test_when_finished "git -C super reset --hard $ORIG" && | |
027771fc HV |
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" && | |
b6188213 | 132 | test-tool submodule-config \ |
027771fc HV |
133 | HEAD b \ |
134 | HEAD submodule \ | |
135 | >actual && | |
996df4d0 | 136 | test_cmp expect_error actual |
027771fc HV |
137 | ) |
138 | ' | |
139 | ||
cc74a4ac | 140 | test_expect_success 'reading submodules config from the working tree' ' |
2502ffc0 AO |
141 | (cd super && |
142 | echo "../submodule" >expect && | |
cc74a4ac | 143 | test-tool submodule config-list submodule.submodule.url >actual && |
2502ffc0 AO |
144 | test_cmp expect actual |
145 | ) | |
146 | ' | |
147 | ||
cc74a4ac | 148 | test_expect_success 'unsetting submodules config from the working tree' ' |
c89c4942 | 149 | (cd super && |
cc74a4ac ÆAB |
150 | test-tool submodule config-unset submodule.submodule.url && |
151 | test-tool submodule config-list submodule.submodule.url >actual && | |
c89c4942 DL |
152 | test_must_be_empty actual |
153 | ) | |
154 | ' | |
155 | ||
156 | ||
cc74a4ac | 157 | test_expect_success 'writing submodules config' ' |
2502ffc0 AO |
158 | (cd super && |
159 | echo "new_url" >expect && | |
cc74a4ac ÆAB |
160 | test-tool submodule config-set submodule.submodule.url "new_url" && |
161 | test-tool submodule config-list submodule.submodule.url >actual && | |
2502ffc0 AO |
162 | test_cmp expect actual |
163 | ) | |
164 | ' | |
165 | ||
cc74a4ac | 166 | test_expect_success 'overwriting unstaged submodules config' ' |
2502ffc0 AO |
167 | test_when_finished "git -C super checkout .gitmodules" && |
168 | (cd super && | |
169 | echo "newer_url" >expect && | |
cc74a4ac ÆAB |
170 | test-tool submodule config-set submodule.submodule.url "newer_url" && |
171 | test-tool submodule config-list submodule.submodule.url >actual && | |
2502ffc0 AO |
172 | test_cmp expect actual |
173 | ) | |
174 | ' | |
175 | ||
b5c259f2 | 176 | test_expect_success 'writeable .gitmodules when it is in the working tree' ' |
cc74a4ac | 177 | test-tool -C super submodule config-writeable |
b5c259f2 AO |
178 | ' |
179 | ||
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" && | |
cc74a4ac | 186 | test-tool submodule config-writeable |
b5c259f2 AO |
187 | ) |
188 | ' | |
189 | ||
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 && | |
cc74a4ac | 194 | test_must_fail test-tool submodule config-writeable |
b5c259f2 AO |
195 | ) |
196 | ' | |
197 | ||
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 && | |
cc74a4ac | 203 | test_must_fail test-tool submodule config-writeable |
b5c259f2 AO |
204 | ) |
205 | ' | |
206 | ||
76e9bdc4 AO |
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 && | |
cc74a4ac | 211 | test-tool submodule config-set submodule.submodule.url "staged_url" && |
76e9bdc4 AO |
212 | git add .gitmodules && |
213 | rm -f .gitmodules && | |
214 | echo "staged_url" >expect && | |
cc74a4ac | 215 | test-tool submodule config-list submodule.submodule.url >actual && |
76e9bdc4 AO |
216 | test_cmp expect actual |
217 | ) | |
218 | ' | |
219 | ||
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 && | |
cc74a4ac | 226 | test-tool submodule config-list submodule.submodule.url >actual && |
76e9bdc4 AO |
227 | test_cmp expect actual |
228 | ) | |
229 | ' | |
230 | ||
2b1257e4 AO |
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 | |
246 | ) | |
247 | ' | |
248 | ||
581d2fd9 | 249 | test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' ' |
2b1257e4 AO |
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 && | |
581d2fd9 | 256 | test_must_be_empty warning && |
2b1257e4 AO |
257 | test_cmp expect actual |
258 | ) | |
259 | ' | |
260 | ||
959b5455 | 261 | test_done |