]>
Commit | Line | Data |
---|---|---|
88961ef2 LH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Lars Hjemli | |
4 | # | |
5 | ||
6 | test_description='Basic porcelain support for submodules | |
7 | ||
8 | This test tries to verify basic sanity of the init, update and status | |
47a528ad | 9 | subcommands of git submodule. |
88961ef2 LH |
10 | ' |
11 | ||
12 | . ./test-lib.sh | |
13 | ||
14 | # | |
15 | # Test setup: | |
a2d93aea | 16 | # -create a repository in directory init |
88961ef2 | 17 | # -add a couple of files |
a2d93aea | 18 | # -add directory init to 'superproject', this creates a DIRLINK entry |
88961ef2 | 19 | # -add a couple of regular files to enable testing of submodule filtering |
a2d93aea | 20 | # -mv init subrepo |
941987a5 | 21 | # -add an entry to .gitmodules for submodule 'example' |
88961ef2 LH |
22 | # |
23 | test_expect_success 'Prepare submodule testing' ' | |
0cf73755 | 24 | : > t && |
47a528ad NS |
25 | git add t && |
26 | git commit -m "initial commit" && | |
0cf73755 | 27 | git branch initial HEAD && |
a2d93aea JH |
28 | mkdir init && |
29 | cd init && | |
5be60078 | 30 | git init && |
88961ef2 | 31 | echo a >a && |
5be60078 | 32 | git add a && |
47a528ad NS |
33 | git commit -m "submodule commit 1" && |
34 | git tag -a -m "rev-1" rev-1 && | |
5be60078 | 35 | rev1=$(git rev-parse HEAD) && |
88961ef2 LH |
36 | if test -z "$rev1" |
37 | then | |
5be60078 | 38 | echo "[OOPS] submodule git rev-parse returned nothing" |
88961ef2 LH |
39 | false |
40 | fi && | |
41 | cd .. && | |
42 | echo a >a && | |
43 | echo z >z && | |
a2d93aea | 44 | git add a init z && |
47a528ad | 45 | git commit -m "super commit 1" && |
a2d93aea JH |
46 | mv init .subrepo && |
47 | GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git | |
941987a5 LH |
48 | ' |
49 | ||
ac8463d2 MG |
50 | test_expect_success 'Prepare submodule add testing' ' |
51 | submodurl=$(pwd) | |
52 | ( | |
53 | mkdir addtest && | |
54 | cd addtest && | |
55 | git init | |
56 | ) | |
57 | ' | |
58 | ||
59 | test_expect_success 'submodule add' ' | |
60 | ( | |
61 | cd addtest && | |
62 | git submodule add "$submodurl" submod && | |
63 | git submodule init | |
64 | ) | |
65 | ' | |
66 | ||
ea10b60c BJ |
67 | test_expect_success 'submodule add --branch' ' |
68 | ( | |
69 | cd addtest && | |
70 | git submodule add -b initial "$submodurl" submod-branch && | |
71 | git submodule init && | |
72 | cd submod-branch && | |
73 | git branch | grep initial | |
74 | ) | |
75 | ' | |
76 | ||
db75ada5 | 77 | test_expect_success 'submodule add with ./ in path' ' |
ac8463d2 MG |
78 | ( |
79 | cd addtest && | |
80 | git submodule add "$submodurl" ././dotsubmod/./frotz/./ && | |
81 | git submodule init | |
82 | ) | |
83 | ' | |
84 | ||
db75ada5 | 85 | test_expect_success 'submodule add with // in path' ' |
ac8463d2 MG |
86 | ( |
87 | cd addtest && | |
88 | git submodule add "$submodurl" slashslashsubmod///frotz// && | |
89 | git submodule init | |
90 | ) | |
91 | ' | |
92 | ||
db75ada5 | 93 | test_expect_success 'submodule add with /.. in path' ' |
ac8463d2 MG |
94 | ( |
95 | cd addtest && | |
96 | git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && | |
97 | git submodule init | |
98 | ) | |
99 | ' | |
100 | ||
db75ada5 | 101 | test_expect_success 'submodule add with ./, /.. and // in path' ' |
ac8463d2 MG |
102 | ( |
103 | cd addtest && | |
104 | git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && | |
105 | git submodule init | |
106 | ) | |
107 | ' | |
108 | ||
941987a5 | 109 | test_expect_success 'status should fail for unmapped paths' ' |
47a528ad | 110 | if git submodule status |
941987a5 LH |
111 | then |
112 | echo "[OOPS] submodule status succeeded" | |
113 | false | |
a2d93aea | 114 | elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init |
941987a5 | 115 | then |
5be60078 | 116 | echo "[OOPS] git config failed to update .gitmodules" |
941987a5 LH |
117 | false |
118 | fi | |
88961ef2 LH |
119 | ' |
120 | ||
121 | test_expect_success 'status should only print one line' ' | |
47a528ad | 122 | lines=$(git submodule status | wc -l) && |
88961ef2 LH |
123 | test $lines = 1 |
124 | ' | |
125 | ||
126 | test_expect_success 'status should initially be "missing"' ' | |
47a528ad | 127 | git submodule status | grep "^-$rev1" |
88961ef2 LH |
128 | ' |
129 | ||
211b7f19 | 130 | test_expect_success 'init should register submodule url in .git/config' ' |
47a528ad | 131 | git submodule init && |
5be60078 | 132 | url=$(git config submodule.example.url) && |
a2d93aea | 133 | if test "$url" != "git://example.com/init.git" |
211b7f19 LH |
134 | then |
135 | echo "[OOPS] init succeeded but submodule url is wrong" | |
136 | false | |
d492b31c | 137 | elif test_must_fail git config submodule.example.url ./.subrepo |
211b7f19 LH |
138 | then |
139 | echo "[OOPS] init succeeded but update of url failed" | |
140 | false | |
141 | fi | |
142 | ' | |
143 | ||
144 | test_expect_success 'update should fail when path is used by a file' ' | |
a2d93aea | 145 | echo "hello" >init && |
47a528ad | 146 | if git submodule update |
88961ef2 | 147 | then |
211b7f19 | 148 | echo "[OOPS] update should have failed" |
88961ef2 | 149 | false |
a2d93aea | 150 | elif test "$(cat init)" != "hello" |
88961ef2 | 151 | then |
a2d93aea | 152 | echo "[OOPS] update failed but init file was molested" |
88961ef2 LH |
153 | false |
154 | else | |
a2d93aea | 155 | rm init |
88961ef2 LH |
156 | fi |
157 | ' | |
158 | ||
211b7f19 | 159 | test_expect_success 'update should fail when path is used by a nonempty directory' ' |
a2d93aea JH |
160 | mkdir init && |
161 | echo "hello" >init/a && | |
47a528ad | 162 | if git submodule update |
88961ef2 | 163 | then |
211b7f19 | 164 | echo "[OOPS] update should have failed" |
88961ef2 | 165 | false |
a2d93aea | 166 | elif test "$(cat init/a)" != "hello" |
88961ef2 | 167 | then |
a2d93aea | 168 | echo "[OOPS] update failed but init/a was molested" |
88961ef2 LH |
169 | false |
170 | else | |
a2d93aea | 171 | rm init/a |
88961ef2 LH |
172 | fi |
173 | ' | |
174 | ||
211b7f19 | 175 | test_expect_success 'update should work when path is an empty dir' ' |
a2d93aea JH |
176 | rm -rf init && |
177 | mkdir init && | |
47a528ad | 178 | git submodule update && |
a2d93aea | 179 | head=$(cd init && git rev-parse HEAD) && |
88961ef2 LH |
180 | if test -z "$head" |
181 | then | |
182 | echo "[OOPS] Failed to obtain submodule head" | |
183 | false | |
184 | elif test "$head" != "$rev1" | |
185 | then | |
186 | echo "[OOPS] Submodule head is $head but should have been $rev1" | |
187 | false | |
188 | fi | |
189 | ' | |
190 | ||
211b7f19 | 191 | test_expect_success 'status should be "up-to-date" after update' ' |
47a528ad | 192 | git submodule status | grep "^ $rev1" |
88961ef2 LH |
193 | ' |
194 | ||
195 | test_expect_success 'status should be "modified" after submodule commit' ' | |
a2d93aea | 196 | cd init && |
88961ef2 | 197 | echo b >b && |
5be60078 | 198 | git add b && |
47a528ad | 199 | git commit -m "submodule commit 2" && |
5be60078 | 200 | rev2=$(git rev-parse HEAD) && |
88961ef2 LH |
201 | cd .. && |
202 | if test -z "$rev2" | |
203 | then | |
5be60078 | 204 | echo "[OOPS] submodule git rev-parse returned nothing" |
88961ef2 LH |
205 | false |
206 | fi && | |
47a528ad | 207 | git submodule status | grep "^+$rev2" |
88961ef2 LH |
208 | ' |
209 | ||
210 | test_expect_success 'the --cached sha1 should be rev1' ' | |
47a528ad | 211 | git submodule --cached status | grep "^+$rev1" |
88961ef2 LH |
212 | ' |
213 | ||
5701115a | 214 | test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' |
47a528ad | 215 | git diff | grep "^+Subproject commit $rev2" |
5701115a SV |
216 | ' |
217 | ||
88961ef2 | 218 | test_expect_success 'update should checkout rev1' ' |
47a528ad | 219 | git submodule update init && |
a2d93aea | 220 | head=$(cd init && git rev-parse HEAD) && |
88961ef2 LH |
221 | if test -z "$head" |
222 | then | |
5be60078 | 223 | echo "[OOPS] submodule git rev-parse returned nothing" |
88961ef2 LH |
224 | false |
225 | elif test "$head" != "$rev1" | |
226 | then | |
227 | echo "[OOPS] init did not checkout correct head" | |
228 | false | |
229 | fi | |
230 | ' | |
231 | ||
232 | test_expect_success 'status should be "up-to-date" after update' ' | |
47a528ad | 233 | git submodule status | grep "^ $rev1" |
88961ef2 LH |
234 | ' |
235 | ||
0cf73755 | 236 | test_expect_success 'checkout superproject with subproject already present' ' |
47a528ad NS |
237 | git checkout initial && |
238 | git checkout master | |
0cf73755 SV |
239 | ' |
240 | ||
e06c5a6c SV |
241 | test_expect_success 'apply submodule diff' ' |
242 | git branch second && | |
243 | ( | |
a2d93aea | 244 | cd init && |
e06c5a6c SV |
245 | echo s >s && |
246 | git add s && | |
247 | git commit -m "change subproject" | |
248 | ) && | |
a2d93aea | 249 | git update-index --add init && |
47a528ad NS |
250 | git commit -m "change init" && |
251 | git format-patch -1 --stdout >P.diff && | |
e06c5a6c SV |
252 | git checkout second && |
253 | git apply --index P.diff && | |
254 | D=$(git diff --cached master) && | |
255 | test -z "$D" | |
256 | ' | |
257 | ||
be4d2c83 JS |
258 | test_expect_success 'update --init' ' |
259 | ||
260 | mv init init2 && | |
261 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && | |
262 | git config --remove-section submodule.example | |
263 | git submodule update init > update.out && | |
264 | grep "not initialized" update.out && | |
265 | test ! -d init/.git && | |
266 | git submodule update --init init && | |
267 | test -d init/.git | |
268 | ||
269 | ' | |
270 | ||
2ce53f9b JS |
271 | test_expect_success 'do not add files from a submodule' ' |
272 | ||
273 | git reset --hard && | |
274 | test_must_fail git add init/a | |
275 | ||
276 | ' | |
277 | ||
278 | test_expect_success 'gracefully add submodule with a trailing slash' ' | |
279 | ||
280 | git reset --hard && | |
281 | git commit -m "commit subproject" init && | |
282 | (cd init && | |
283 | echo b > a) && | |
284 | git add init/ && | |
285 | git diff --exit-code --cached init && | |
286 | commit=$(cd init && | |
287 | git commit -m update a >/dev/null && | |
288 | git rev-parse HEAD) && | |
289 | git add init/ && | |
290 | test_must_fail git diff --exit-code --cached init && | |
291 | test $commit = $(git ls-files --stage | | |
292 | sed -n "s/^160000 \([^ ]*\).*/\1/p") | |
293 | ||
294 | ' | |
295 | ||
f3670a57 JS |
296 | test_expect_success 'ls-files gracefully handles trailing slash' ' |
297 | ||
298 | test "init" = "$(git ls-files init/)" | |
299 | ||
300 | ' | |
301 | ||
496917b7 JS |
302 | test_expect_success 'submodule <invalid-path> warns' ' |
303 | ||
304 | git submodule no-such-submodule 2> output.err && | |
305 | grep "^error: .*no-such-submodule" output.err | |
306 | ||
307 | ' | |
308 | ||
1414e578 JL |
309 | test_expect_success 'add submodules without specifying an explicit path' ' |
310 | mkdir repo && | |
311 | cd repo && | |
312 | git init && | |
313 | echo r >r && | |
314 | git add r && | |
315 | git commit -m "repo commit 1" && | |
316 | cd .. && | |
317 | git clone --bare repo/ bare.git && | |
318 | cd addtest && | |
319 | git submodule add "$submodurl/repo" && | |
320 | git config -f .gitmodules submodule.repo.path repo && | |
321 | git submodule add "$submodurl/bare.git" && | |
322 | git config -f .gitmodules submodule.bare.path bare | |
323 | ' | |
324 | ||
88961ef2 | 325 | test_done |