]>
Commit | Line | Data |
---|---|---|
e1970ce4 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test the very basics part #1. | |
7 | ||
8 | The rest of the test suite does not check the basic operation of git | |
9 | plumbing commands to work very carefully. Their job is to concentrate | |
10 | on tricky features that caused bugs in the past to detect regression. | |
11 | ||
12 | This test runs very basic features, like registering things in cache, | |
13 | writing tree, etc. | |
14 | ||
15 | Note that this test *deliberately* hard-codes many expected object | |
16 | IDs. When object ID computation changes, like in the previous case of | |
17 | swapping compression and hashing order, the person who is making the | |
18 | modification *should* take notice and update the test vectors here. | |
19 | ' | |
eea42069 | 20 | |
e1970ce4 JH |
21 | . ./test-lib.sh |
22 | ||
23 | ################################################################ | |
5be60078 | 24 | # git init has been done in an empty repository. |
e1970ce4 JH |
25 | # make sure it is empty. |
26 | ||
1b5b2b64 SL |
27 | test_expect_success '.git/objects should be empty after git init in an empty repo' ' |
28 | find .git/objects -type f -print >should-be-empty && | |
29 | test_line_count = 0 should-be-empty | |
30 | ' | |
e1970ce4 | 31 | |
9106c097 LT |
32 | # also it should have 2 subdirectories; no fan-out anymore, pack, and info. |
33 | # 3 is counting "objects" itself | |
1b5b2b64 SL |
34 | test_expect_success '.git/objects should have 3 subdirectories' ' |
35 | find .git/objects -type d -print >full-of-directories && | |
36 | test_line_count = 3 full-of-directories | |
37 | ' | |
e1970ce4 | 38 | |
41ac414e JH |
39 | ################################################################ |
40 | # Test harness | |
41 | test_expect_success 'success is reported like this' ' | |
1b5b2b64 | 42 | : |
41ac414e JH |
43 | ' |
44 | test_expect_failure 'pretend we have a known breakage' ' | |
1b5b2b64 | 45 | false |
41ac414e | 46 | ' |
7b905119 | 47 | |
565b6fa8 AS |
48 | run_sub_test_lib_test () { |
49 | name="$1" descr="$2" # stdin is the body of the test code | |
50 | mkdir "$name" && | |
51 | ( | |
52 | cd "$name" && | |
53 | cat >"$name.sh" <<-EOF && | |
54 | #!$SHELL_PATH | |
55 | ||
56 | test_description='$descr (run in sub test-lib) | |
57 | ||
58 | This is run in a sub test-lib so that we do not get incorrect | |
59 | passing metrics | |
60 | ' | |
61 | ||
62 | # Point to the t/test-lib.sh, which isn't in ../ as usual | |
63 | . "\$TEST_DIRECTORY"/test-lib.sh | |
64 | EOF | |
65 | cat >>"$name.sh" && | |
66 | chmod +x "$name.sh" && | |
67 | export TEST_DIRECTORY && | |
68 | ./"$name.sh" >out 2>err | |
69 | ) | |
70 | } | |
1b5b2b64 | 71 | |
565b6fa8 AS |
72 | check_sub_test_lib_test () { |
73 | name="$1" # stdin is the expected output from the test | |
74 | ( | |
75 | cd "$name" && | |
76 | ! test -s err && | |
77 | sed -e 's/^> //' -e 's/Z$//' >expect && | |
78 | test_cmp expect out | |
79 | ) | |
80 | } | |
1b5b2b64 | 81 | |
5ebf89e8 AS |
82 | test_expect_success 'pretend we have a fully passing test suite' " |
83 | run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF && | |
84 | for i in 1 2 3 | |
85 | do | |
86 | test_expect_success \"passing test #\$i\" 'true' | |
87 | done | |
88 | test_done | |
89 | EOF | |
90 | check_sub_test_lib_test full-pass <<-\\EOF | |
91 | > ok 1 - passing test #1 | |
92 | > ok 2 - passing test #2 | |
93 | > ok 3 - passing test #3 | |
94 | > # passed all 3 test(s) | |
95 | > 1..3 | |
96 | EOF | |
97 | " | |
1b5b2b64 | 98 | |
5ebf89e8 AS |
99 | test_expect_success 'pretend we have a partially passing test suite' " |
100 | test_must_fail run_sub_test_lib_test \ | |
101 | partial-pass '2/3 tests passing' <<-\\EOF && | |
102 | test_expect_success 'passing test #1' 'true' | |
103 | test_expect_success 'failing test #2' 'false' | |
104 | test_expect_success 'passing test #3' 'true' | |
105 | test_done | |
106 | EOF | |
107 | check_sub_test_lib_test partial-pass <<-\\EOF | |
108 | > ok 1 - passing test #1 | |
109 | > not ok 2 - failing test #2 | |
110 | # false | |
111 | > ok 3 - passing test #3 | |
112 | > # failed 1 among 3 test(s) | |
113 | > 1..3 | |
114 | EOF | |
115 | " | |
1b5b2b64 | 116 | |
5ebf89e8 AS |
117 | test_expect_success 'pretend we have a known breakage' " |
118 | run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF && | |
119 | test_expect_success 'passing test' 'true' | |
120 | test_expect_failure 'pretend we have a known breakage' 'false' | |
121 | test_done | |
122 | EOF | |
123 | check_sub_test_lib_test failing-todo <<-\\EOF | |
124 | > ok 1 - passing test | |
125 | > not ok 2 - pretend we have a known breakage # TODO known breakage | |
126 | > # still have 1 known breakage(s) | |
127 | > # passed all remaining 1 test(s) | |
128 | > 1..2 | |
129 | EOF | |
130 | " | |
1b5b2b64 | 131 | |
565b6fa8 AS |
132 | test_expect_success 'pretend we have fixed a known breakage' " |
133 | run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF && | |
134 | test_expect_failure 'pretend we have fixed a known breakage' 'true' | |
1b5b2b64 SL |
135 | test_done |
136 | EOF | |
565b6fa8 | 137 | check_sub_test_lib_test passing-todo <<-\\EOF |
b73d9a23 AS |
138 | > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished |
139 | > # 1 known breakage(s) vanished; please update test(s) | |
1b5b2b64 SL |
140 | > 1..1 |
141 | EOF | |
7b905119 | 142 | " |
565b6fa8 | 143 | |
b73d9a23 AS |
144 | test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' " |
145 | run_sub_test_lib_test partially-passing-todos \ | |
146 | '2 TODO tests, one passing' <<-\\EOF && | |
147 | test_expect_failure 'pretend we have a known breakage' 'false' | |
148 | test_expect_success 'pretend we have a passing test' 'true' | |
149 | test_expect_failure 'pretend we have fixed another known breakage' 'true' | |
150 | test_done | |
151 | EOF | |
152 | check_sub_test_lib_test partially-passing-todos <<-\\EOF | |
153 | > not ok 1 - pretend we have a known breakage # TODO known breakage | |
154 | > ok 2 - pretend we have a passing test | |
155 | > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished | |
156 | > # 1 known breakage(s) vanished; please update test(s) | |
157 | > # still have 1 known breakage(s) | |
158 | > # passed all remaining 1 test(s) | |
159 | > 1..3 | |
160 | EOF | |
161 | " | |
162 | ||
5ebf89e8 AS |
163 | test_expect_success 'pretend we have a pass, fail, and known breakage' " |
164 | test_must_fail run_sub_test_lib_test \ | |
165 | mixed-results1 'mixed results #1' <<-\\EOF && | |
166 | test_expect_success 'passing test' 'true' | |
167 | test_expect_success 'failing test' 'false' | |
168 | test_expect_failure 'pretend we have a known breakage' 'false' | |
169 | test_done | |
170 | EOF | |
171 | check_sub_test_lib_test mixed-results1 <<-\\EOF | |
172 | > ok 1 - passing test | |
173 | > not ok 2 - failing test | |
174 | > # false | |
175 | > not ok 3 - pretend we have a known breakage # TODO known breakage | |
176 | > # still have 1 known breakage(s) | |
177 | > # failed 1 among remaining 2 test(s) | |
178 | > 1..3 | |
179 | EOF | |
180 | " | |
181 | ||
182 | test_expect_success 'pretend we have a mix of all possible results' " | |
183 | test_must_fail run_sub_test_lib_test \ | |
184 | mixed-results2 'mixed results #2' <<-\\EOF && | |
185 | test_expect_success 'passing test' 'true' | |
186 | test_expect_success 'passing test' 'true' | |
187 | test_expect_success 'passing test' 'true' | |
188 | test_expect_success 'passing test' 'true' | |
189 | test_expect_success 'failing test' 'false' | |
190 | test_expect_success 'failing test' 'false' | |
191 | test_expect_success 'failing test' 'false' | |
192 | test_expect_failure 'pretend we have a known breakage' 'false' | |
193 | test_expect_failure 'pretend we have a known breakage' 'false' | |
194 | test_expect_failure 'pretend we have fixed a known breakage' 'true' | |
195 | test_done | |
196 | EOF | |
197 | check_sub_test_lib_test mixed-results2 <<-\\EOF | |
198 | > ok 1 - passing test | |
199 | > ok 2 - passing test | |
200 | > ok 3 - passing test | |
201 | > ok 4 - passing test | |
202 | > not ok 5 - failing test | |
203 | > # false | |
204 | > not ok 6 - failing test | |
205 | > # false | |
206 | > not ok 7 - failing test | |
207 | > # false | |
208 | > not ok 8 - pretend we have a known breakage # TODO known breakage | |
209 | > not ok 9 - pretend we have a known breakage # TODO known breakage | |
b73d9a23 AS |
210 | > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished |
211 | > # 1 known breakage(s) vanished; please update test(s) | |
5ebf89e8 | 212 | > # still have 2 known breakage(s) |
b73d9a23 | 213 | > # failed 3 among remaining 7 test(s) |
5ebf89e8 AS |
214 | > 1..10 |
215 | EOF | |
216 | " | |
217 | ||
a7bb3940 JS |
218 | test_set_prereq HAVEIT |
219 | haveit=no | |
220 | test_expect_success HAVEIT 'test runs if prerequisite is satisfied' ' | |
1b5b2b64 SL |
221 | test_have_prereq HAVEIT && |
222 | haveit=yes | |
a7bb3940 JS |
223 | ' |
224 | donthaveit=yes | |
225 | test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' ' | |
1b5b2b64 | 226 | donthaveit=no |
a7bb3940 JS |
227 | ' |
228 | if test $haveit$donthaveit != yesyes | |
229 | then | |
230 | say "bug in test framework: prerequisite tags do not work reliably" | |
93a57246 ÆAB |
231 | exit 1 |
232 | fi | |
233 | ||
234 | test_set_prereq HAVETHIS | |
235 | haveit=no | |
236 | test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' ' | |
1b5b2b64 SL |
237 | test_have_prereq HAVEIT && |
238 | test_have_prereq HAVETHIS && | |
239 | haveit=yes | |
93a57246 ÆAB |
240 | ' |
241 | donthaveit=yes | |
242 | test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' ' | |
1b5b2b64 | 243 | donthaveit=no |
93a57246 | 244 | ' |
ce60653e ÆAB |
245 | donthaveiteither=yes |
246 | test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' ' | |
1b5b2b64 | 247 | donthaveiteither=no |
ce60653e ÆAB |
248 | ' |
249 | if test $haveit$donthaveit$donthaveiteither != yesyesyes | |
93a57246 ÆAB |
250 | then |
251 | say "bug in test framework: multiple prerequisite tags do not work reliably" | |
a7bb3940 JS |
252 | exit 1 |
253 | fi | |
41ac414e | 254 | |
bdccd3c1 JK |
255 | test_lazy_prereq LAZY_TRUE true |
256 | havetrue=no | |
257 | test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' ' | |
258 | havetrue=yes | |
259 | ' | |
260 | donthavetrue=yes | |
261 | test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' ' | |
262 | donthavetrue=no | |
263 | ' | |
264 | ||
265 | if test "$havetrue$donthavetrue" != yesyes | |
266 | then | |
267 | say 'bug in test framework: lazy prerequisites do not work' | |
268 | exit 1 | |
269 | fi | |
270 | ||
271 | test_lazy_prereq LAZY_FALSE false | |
272 | nothavefalse=no | |
273 | test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' ' | |
274 | nothavefalse=yes | |
275 | ' | |
276 | havefalse=yes | |
277 | test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' ' | |
278 | havefalse=no | |
279 | ' | |
280 | ||
281 | if test "$nothavefalse$havefalse" != yesyes | |
282 | then | |
283 | say 'bug in test framework: negative lazy prerequisites do not work' | |
284 | exit 1 | |
285 | fi | |
286 | ||
b6b0afdc JN |
287 | clean=no |
288 | test_expect_success 'tests clean up after themselves' ' | |
1b5b2b64 | 289 | test_when_finished clean=yes |
b6b0afdc JN |
290 | ' |
291 | ||
892e6f7e | 292 | if test $clean != yes |
b6b0afdc | 293 | then |
892e6f7e | 294 | say "bug in test framework: basic cleanup command does not work reliably" |
b6b0afdc JN |
295 | exit 1 |
296 | fi | |
297 | ||
892e6f7e | 298 | test_expect_success 'tests clean up even on failures' " |
565b6fa8 AS |
299 | test_must_fail run_sub_test_lib_test \ |
300 | failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF && | |
1b5b2b64 SL |
301 | test_expect_success 'tests clean up even after a failure' ' |
302 | touch clean-after-failure && | |
303 | test_when_finished rm clean-after-failure && | |
304 | (exit 1) | |
305 | ' | |
306 | test_expect_success 'failure to clean up causes the test to fail' ' | |
307 | test_when_finished \"(exit 2)\" | |
308 | ' | |
309 | test_done | |
1b5b2b64 | 310 | EOF |
565b6fa8 | 311 | check_sub_test_lib_test failing-cleanup <<-\\EOF |
5e5c006e | 312 | > not ok 1 - tests clean up even after a failure |
1b5b2b64 SL |
313 | > # Z |
314 | > # touch clean-after-failure && | |
315 | > # test_when_finished rm clean-after-failure && | |
316 | > # (exit 1) | |
317 | > # Z | |
5e5c006e | 318 | > not ok 2 - failure to clean up causes the test to fail |
1b5b2b64 SL |
319 | > # Z |
320 | > # test_when_finished \"(exit 2)\" | |
321 | > # Z | |
322 | > # failed 2 among 2 test(s) | |
323 | > 1..2 | |
324 | EOF | |
892e6f7e ÆAB |
325 | " |
326 | ||
e1970ce4 JH |
327 | ################################################################ |
328 | # Basics of the basics | |
329 | ||
330 | # updating a new file without --add should fail. | |
1b5b2b64 SL |
331 | test_expect_success 'git update-index without --add should fail adding' ' |
332 | test_must_fail git update-index should-be-empty | |
41ac414e | 333 | ' |
e1970ce4 JH |
334 | |
335 | # and with --add it should succeed, even if it is empty (it used to fail). | |
1b5b2b64 SL |
336 | test_expect_success 'git update-index with --add should succeed' ' |
337 | git update-index --add should-be-empty | |
338 | ' | |
e1970ce4 | 339 | |
1b5b2b64 SL |
340 | test_expect_success 'writing tree out with git write-tree' ' |
341 | tree=$(git write-tree) | |
342 | ' | |
e1970ce4 JH |
343 | |
344 | # we know the shape and contents of the tree and know the object ID for it. | |
1b5b2b64 SL |
345 | test_expect_success 'validate object ID of a known tree' ' |
346 | test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a | |
347 | ' | |
e1970ce4 JH |
348 | |
349 | # Removing paths. | |
1b5b2b64 SL |
350 | test_expect_success 'git update-index without --remove should fail removing' ' |
351 | rm -f should-be-empty full-of-directories && | |
352 | test_must_fail git update-index should-be-empty | |
41ac414e | 353 | ' |
e1970ce4 | 354 | |
1b5b2b64 SL |
355 | test_expect_success 'git update-index with --remove should be able to remove' ' |
356 | git update-index --remove should-be-empty | |
357 | ' | |
e1970ce4 JH |
358 | |
359 | # Empty tree can be written with recent write-tree. | |
1b5b2b64 SL |
360 | test_expect_success 'git write-tree should be able to write an empty tree' ' |
361 | tree=$(git write-tree) | |
362 | ' | |
e1970ce4 | 363 | |
1b5b2b64 SL |
364 | test_expect_success 'validate object ID of a known tree' ' |
365 | test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
366 | ' | |
e1970ce4 JH |
367 | |
368 | # Various types of objects | |
1b5b2b64 | 369 | |
704a3143 JS |
370 | # Some filesystems do not support symblic links; on such systems |
371 | # some expected values are different | |
704a3143 JS |
372 | if test_have_prereq SYMLINKS |
373 | then | |
704a3143 JS |
374 | expectfilter=cat |
375 | expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b | |
376 | expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3 | |
377 | expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2 | |
378 | else | |
379 | expectfilter='grep -v sym' | |
380 | expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46 | |
381 | expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325 | |
382 | expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f | |
383 | fi | |
384 | ||
1b5b2b64 SL |
385 | |
386 | test_expect_success 'adding various types of objects with git update-index --add' ' | |
387 | mkdir path2 path3 path3/subp3 && | |
388 | paths="path0 path2/file2 path3/file3 path3/subp3/file3" && | |
389 | ( | |
390 | for p in $paths | |
391 | do | |
392 | echo "hello $p" >$p || exit 1 | |
393 | if test_have_prereq SYMLINKS | |
394 | then | |
395 | ln -s "hello $p" ${p}sym || exit 1 | |
396 | fi | |
397 | done | |
398 | ) && | |
399 | find path* ! -type d -print | xargs git update-index --add | |
400 | ' | |
e1970ce4 JH |
401 | |
402 | # Show them and see that matches what we expect. | |
1b5b2b64 SL |
403 | test_expect_success 'showing stage with git ls-files --stage' ' |
404 | git ls-files --stage >current | |
405 | ' | |
406 | ||
407 | test_expect_success 'validate git ls-files output for a known tree' ' | |
408 | $expectfilter >expected <<-\EOF && | |
409 | 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0 | |
410 | 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym | |
411 | 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2 | |
412 | 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym | |
413 | 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3 | |
414 | 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym | |
415 | 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3 | |
416 | 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym | |
417 | EOF | |
418 | test_cmp expected current | |
419 | ' | |
420 | ||
421 | test_expect_success 'writing tree out with git write-tree' ' | |
422 | tree=$(git write-tree) | |
423 | ' | |
424 | ||
425 | test_expect_success 'validate object ID for a known tree' ' | |
426 | test "$tree" = "$expectedtree" | |
427 | ' | |
428 | ||
429 | test_expect_success 'showing tree with git ls-tree' ' | |
430 | git ls-tree $tree >current | |
431 | ' | |
432 | ||
433 | test_expect_success SYMLINKS 'git ls-tree output for a known tree' ' | |
434 | cat >expected <<-\EOF && | |
435 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 | |
436 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
437 | 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 | |
438 | 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 | |
439 | EOF | |
440 | test_cmp expected current | |
441 | ' | |
e1970ce4 | 442 | |
246cc52f JH |
443 | # This changed in ls-tree pathspec change -- recursive does |
444 | # not show tree nodes anymore. | |
1b5b2b64 SL |
445 | test_expect_success 'showing tree with git ls-tree -r' ' |
446 | git ls-tree -r $tree >current | |
447 | ' | |
448 | ||
449 | test_expect_success 'git ls-tree -r output for a known tree' ' | |
450 | $expectfilter >expected <<-\EOF && | |
451 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 | |
452 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
453 | 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 | |
454 | 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym | |
455 | 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 | |
456 | 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym | |
457 | 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 | |
458 | 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym | |
459 | EOF | |
460 | test_cmp expected current | |
461 | ' | |
e1970ce4 | 462 | |
fdeb6bf5 | 463 | # But with -r -t we can have both. |
1b5b2b64 SL |
464 | test_expect_success 'showing tree with git ls-tree -r -t' ' |
465 | git ls-tree -r -t $tree >current | |
466 | ' | |
3d12d0cf | 467 | |
1b5b2b64 SL |
468 | test_expect_success SYMLINKS 'git ls-tree -r output for a known tree' ' |
469 | cat >expected <<-\EOF && | |
470 | 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0 | |
471 | 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym | |
472 | 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2 | |
473 | 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2 | |
474 | 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym | |
475 | 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3 | |
476 | 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3 | |
477 | 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym | |
478 | 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3 | |
479 | 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3 | |
480 | 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym | |
481 | EOF | |
482 | test_cmp expected current | |
483 | ' | |
3d12d0cf | 484 | |
1b5b2b64 SL |
485 | test_expect_success 'writing partial tree out with git write-tree --prefix' ' |
486 | ptree=$(git write-tree --prefix=path3) | |
41ac414e | 487 | ' |
3d12d0cf | 488 | |
1b5b2b64 SL |
489 | test_expect_success 'validate object ID for a known tree' ' |
490 | test "$ptree" = "$expectedptree1" | |
491 | ' | |
492 | ||
493 | test_expect_success 'writing partial tree out with git write-tree --prefix' ' | |
494 | ptree=$(git write-tree --prefix=path3/subp3) | |
495 | ' | |
496 | ||
497 | test_expect_success 'validate object ID for a known tree' ' | |
498 | test "$ptree" = "$expectedptree2" | |
499 | ' | |
500 | ||
501 | test_expect_success 'put invalid objects into the index' ' | |
502 | rm -f .git/index && | |
503 | cat >badobjects <<-\EOF && | |
504 | 100644 blob 1000000000000000000000000000000000000000 dir/file1 | |
505 | 100644 blob 2000000000000000000000000000000000000000 dir/file2 | |
506 | 100644 blob 3000000000000000000000000000000000000000 dir/file3 | |
507 | 100644 blob 4000000000000000000000000000000000000000 dir/file4 | |
508 | 100644 blob 5000000000000000000000000000000000000000 dir/file5 | |
509 | EOF | |
510 | git update-index --index-info <badobjects | |
511 | ' | |
512 | ||
513 | test_expect_success 'writing this tree without --missing-ok' ' | |
514 | test_must_fail git write-tree | |
515 | ' | |
516 | ||
517 | test_expect_success 'writing this tree with --missing-ok' ' | |
518 | git write-tree --missing-ok | |
519 | ' | |
3d12d0cf JS |
520 | |
521 | ||
e1970ce4 | 522 | ################################################################ |
1b5b2b64 SL |
523 | test_expect_success 'git read-tree followed by write-tree should be idempotent' ' |
524 | rm -f .git/index | |
525 | git read-tree $tree && | |
526 | test -f .git/index && | |
527 | newtree=$(git write-tree) && | |
528 | test "$newtree" = "$tree" | |
529 | ' | |
530 | ||
531 | test_expect_success 'validate git diff-files output for a know cache/work tree state' ' | |
532 | $expectfilter >expected <<\EOF && | |
b6d8f309 JH |
533 | :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0 |
534 | :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym | |
535 | :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2 | |
536 | :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym | |
537 | :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3 | |
538 | :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym | |
539 | :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3 | |
540 | :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym | |
e1970ce4 | 541 | EOF |
1b5b2b64 SL |
542 | git diff-files >current && |
543 | test_cmp current expected | |
544 | ' | |
e1970ce4 | 545 | |
1b5b2b64 SL |
546 | test_expect_success 'git update-index --refresh should succeed' ' |
547 | git update-index --refresh | |
548 | ' | |
e1970ce4 | 549 | |
1b5b2b64 SL |
550 | test_expect_success 'no diff after checkout and git update-index --refresh' ' |
551 | git diff-files >current && | |
552 | cmp -s current /dev/null | |
553 | ' | |
e1970ce4 | 554 | |
9af0b8db | 555 | ################################################################ |
704a3143 | 556 | P=$expectedtree |
1b5b2b64 SL |
557 | |
558 | test_expect_success 'git commit-tree records the correct tree in a commit' ' | |
559 | commit0=$(echo NO | git commit-tree $P) && | |
560 | tree=$(git show --pretty=raw $commit0 | | |
561 | sed -n -e "s/^tree //p" -e "/^author /q") && | |
562 | test "z$tree" = "z$P" | |
563 | ' | |
564 | ||
565 | test_expect_success 'git commit-tree records the correct parent in a commit' ' | |
566 | commit1=$(echo NO | git commit-tree $P -p $commit0) && | |
567 | parent=$(git show --pretty=raw $commit1 | | |
568 | sed -n -e "s/^parent //p" -e "/^author /q") && | |
569 | test "z$commit0" = "z$parent" | |
570 | ' | |
571 | ||
572 | test_expect_success 'git commit-tree omits duplicated parent in a commit' ' | |
573 | commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && | |
574 | parent=$(git show --pretty=raw $commit2 | | |
575 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
576 | sort -u) && | |
577 | test "z$commit0" = "z$parent" && | |
578 | numparent=$(git show --pretty=raw $commit2 | | |
579 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
580 | wc -l) && | |
581 | test $numparent = 1 | |
582 | ' | |
9af0b8db | 583 | |
81a361be JH |
584 | test_expect_success 'update-index D/F conflict' ' |
585 | mv path0 tmp && | |
586 | mv path2 path0 && | |
587 | mv tmp path2 && | |
588 | git update-index --add --replace path2 path0/file2 && | |
589 | numpath0=$(git ls-files path0 | wc -l) && | |
590 | test $numpath0 = 1 | |
591 | ' | |
592 | ||
7fec10b7 JH |
593 | test_expect_success 'very long name in the index handled sanely' ' |
594 | ||
595 | a=a && # 1 | |
596 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16 | |
597 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256 | |
598 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096 | |
599 | a=${a}q && | |
600 | ||
601 | >path4 && | |
602 | git update-index --add path4 && | |
603 | ( | |
604 | git ls-files -s path4 | | |
605 | sed -e "s/ .*/ /" | | |
606 | tr -d "\012" | |
607 | echo "$a" | |
608 | ) | git update-index --index-info && | |
609 | len=$(git ls-files "a*" | wc -c) && | |
610 | test $len = 4098 | |
611 | ' | |
612 | ||
e1970ce4 | 613 | test_done |