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