3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Test the very basics part #1.
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.
12 This test runs very basic features, like registering things in cache,
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.
28 # This test is an experiment to check whether any Git users are using
29 # Shells that don't support the "local" keyword. "local" is not
30 # POSIX-standard, but it is very widely supported by POSIX-compliant
31 # shells, and if it doesn't cause problems for people, we would like
32 # to be able to use it in Git code.
34 # For now, this is the only test that requires "local". If your shell
35 # fails this test, you can ignore the failure, but please report the
36 # problem to the Git mailing list <git@vger.kernel.org>, as it might
37 # convince us to continue avoiding the use of "local".
38 test_expect_success
'verify that the running shell supports "local"' '
40 echo "local" >expected1 &&
41 try_local_x >actual1 &&
42 test_cmp expected1 actual1 &&
43 echo "notlocal" >expected2 &&
45 test_cmp expected2 actual2
48 ################################################################
49 # git init has been done in an empty repository.
50 # make sure it is empty.
52 test_expect_success
'.git/objects should be empty after git init in an empty repo' '
53 find .git/objects -type f -print >should-be-empty &&
54 test_line_count = 0 should-be-empty
57 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
58 # 3 is counting "objects" itself
59 test_expect_success
'.git/objects should have 3 subdirectories' '
60 find .git/objects -type d -print >full-of-directories &&
61 test_line_count = 3 full-of-directories
64 ################################################################
66 test_expect_success
'success is reported like this' '
70 _run_sub_test_lib_test_common
() {
71 neg
="$1" name
="$2" descr
="$3" # stdin is the body of the test code
75 # Pretend we're not running under a test harness, whether we
76 # are or not. The test-lib output depends on the setting of
77 # this variable, so we need a stable setting under which to run
79 sane_unset HARNESS_ACTIVE
&&
81 cat >"$name.sh" <<-EOF &&
84 test_description='$descr (run in sub test-lib)
86 This is run in a sub test-lib so that we do not get incorrect
90 # Point to the t/test-lib.sh, which isn't in ../ as usual
91 . "\$TEST_DIRECTORY"/test-lib.sh
94 chmod +x
"$name.sh" &&
95 export TEST_DIRECTORY
&&
96 TEST_OUTPUT_DIRECTORY
=$
(pwd) &&
97 export TEST_OUTPUT_DIRECTORY
&&
100 .
/"$name.sh" "$@" >out
2>err
102 ! .
/"$name.sh" "$@" >out
2>err
107 run_sub_test_lib_test
() {
108 _run_sub_test_lib_test_common
'' "$@"
111 run_sub_test_lib_test_err
() {
112 _run_sub_test_lib_test_common
'!' "$@"
115 check_sub_test_lib_test
() {
116 name
="$1" # stdin is the expected output from the test
119 test_must_be_empty err
&&
120 sed -e 's/^> //' -e 's/Z$//' >expect
&&
125 check_sub_test_lib_test_err
() {
126 name
="$1" # stdin is the expected output from the test
127 # expected error output is in descriptior 3
130 sed -e 's/^> //' -e 's/Z$//' >expect.out
&&
131 test_cmp expect.out out
&&
132 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err
&&
133 test_cmp expect.err err
137 test_expect_success
'pretend we have a fully passing test suite' "
138 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
141 test_expect_success \"passing test #\$i\" 'true'
145 check_sub_test_lib_test full-pass <<-\\EOF
146 > ok 1 - passing test #1
147 > ok 2 - passing test #2
148 > ok 3 - passing test #3
149 > # passed all 3 test(s)
154 test_expect_success
'pretend we have a partially passing test suite' "
155 test_must_fail run_sub_test_lib_test \
156 partial-pass '2/3 tests passing' <<-\\EOF &&
157 test_expect_success 'passing test #1' 'true'
158 test_expect_success 'failing test #2' 'false'
159 test_expect_success 'passing test #3' 'true'
162 check_sub_test_lib_test partial-pass <<-\\EOF
163 > ok 1 - passing test #1
164 > not ok 2 - failing test #2
166 > ok 3 - passing test #3
167 > # failed 1 among 3 test(s)
172 test_expect_success
'pretend we have a known breakage' "
173 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
174 test_expect_success 'passing test' 'true'
175 test_expect_failure 'pretend we have a known breakage' 'false'
178 check_sub_test_lib_test failing-todo <<-\\EOF
179 > ok 1 - passing test
180 > not ok 2 - pretend we have a known breakage # TODO known breakage
181 > # still have 1 known breakage(s)
182 > # passed all remaining 1 test(s)
187 test_expect_success
'pretend we have fixed a known breakage' "
188 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
189 test_expect_failure 'pretend we have fixed a known breakage' 'true'
192 check_sub_test_lib_test passing-todo <<-\\EOF
193 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
194 > # 1 known breakage(s) vanished; please update test(s)
199 test_expect_success
'pretend we have fixed one of two known breakages (run in sub test-lib)' "
200 run_sub_test_lib_test partially-passing-todos \
201 '2 TODO tests, one passing' <<-\\EOF &&
202 test_expect_failure 'pretend we have a known breakage' 'false'
203 test_expect_success 'pretend we have a passing test' 'true'
204 test_expect_failure 'pretend we have fixed another known breakage' 'true'
207 check_sub_test_lib_test partially-passing-todos <<-\\EOF
208 > not ok 1 - pretend we have a known breakage # TODO known breakage
209 > ok 2 - pretend we have a passing test
210 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
211 > # 1 known breakage(s) vanished; please update test(s)
212 > # still have 1 known breakage(s)
213 > # passed all remaining 1 test(s)
218 test_expect_success
'pretend we have a pass, fail, and known breakage' "
219 test_must_fail run_sub_test_lib_test \
220 mixed-results1 'mixed results #1' <<-\\EOF &&
221 test_expect_success 'passing test' 'true'
222 test_expect_success 'failing test' 'false'
223 test_expect_failure 'pretend we have a known breakage' 'false'
226 check_sub_test_lib_test mixed-results1 <<-\\EOF
227 > ok 1 - passing test
228 > not ok 2 - failing test
230 > not ok 3 - pretend we have a known breakage # TODO known breakage
231 > # still have 1 known breakage(s)
232 > # failed 1 among remaining 2 test(s)
237 test_expect_success
'pretend we have a mix of all possible results' "
238 test_must_fail run_sub_test_lib_test \
239 mixed-results2 'mixed results #2' <<-\\EOF &&
240 test_expect_success 'passing test' 'true'
241 test_expect_success 'passing test' 'true'
242 test_expect_success 'passing test' 'true'
243 test_expect_success 'passing test' 'true'
244 test_expect_success 'failing test' 'false'
245 test_expect_success 'failing test' 'false'
246 test_expect_success 'failing test' 'false'
247 test_expect_failure 'pretend we have a known breakage' 'false'
248 test_expect_failure 'pretend we have a known breakage' 'false'
249 test_expect_failure 'pretend we have fixed a known breakage' 'true'
252 check_sub_test_lib_test mixed-results2 <<-\\EOF
253 > ok 1 - passing test
254 > ok 2 - passing test
255 > ok 3 - passing test
256 > ok 4 - passing test
257 > not ok 5 - failing test
259 > not ok 6 - failing test
261 > not ok 7 - failing test
263 > not ok 8 - pretend we have a known breakage # TODO known breakage
264 > not ok 9 - pretend we have a known breakage # TODO known breakage
265 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
266 > # 1 known breakage(s) vanished; please update test(s)
267 > # still have 2 known breakage(s)
268 > # failed 3 among remaining 7 test(s)
273 test_expect_success
'test --verbose' '
274 test_must_fail run_sub_test_lib_test \
275 test-verbose "test verbose" --verbose <<-\EOF &&
276 test_expect_success "passing test" true
277 test_expect_success "test with output" "echo foo"
278 test_expect_success "failing test" false
281 mv test-verbose/out test-verbose/out+ &&
282 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
283 check_sub_test_lib_test test-verbose <<-\EOF
284 > expecting success: true
285 > ok 1 - passing test
287 > expecting success: echo foo
289 > ok 2 - test with output
291 > expecting success: false
292 > not ok 3 - failing test
295 > # failed 1 among 3 test(s)
300 test_expect_success
'test --verbose-only' '
301 test_must_fail run_sub_test_lib_test \
302 test-verbose-only-2 "test verbose-only=2" \
303 --verbose-only=2 <<-\EOF &&
304 test_expect_success "passing test" true
305 test_expect_success "test with output" "echo foo"
306 test_expect_success "failing test" false
309 check_sub_test_lib_test test-verbose-only-2 <<-\EOF
310 > ok 1 - passing test
312 > expecting success: echo foo
314 > ok 2 - test with output
316 > not ok 3 - failing test
318 > # failed 1 among 3 test(s)
323 test_expect_success
'GIT_SKIP_TESTS' "
325 GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS &&
326 run_sub_test_lib_test git-skip-tests-basic \
327 'GIT_SKIP_TESTS' <<-\\EOF &&
330 test_expect_success \"passing test #\$i\" 'true'
334 check_sub_test_lib_test git-skip-tests-basic <<-\\EOF
335 > ok 1 - passing test #1
336 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
337 > ok 3 - passing test #3
338 > # passed all 3 test(s)
344 test_expect_success
'GIT_SKIP_TESTS several tests' "
346 GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS &&
347 run_sub_test_lib_test git-skip-tests-several \
348 'GIT_SKIP_TESTS several tests' <<-\\EOF &&
351 test_expect_success \"passing test #\$i\" 'true'
355 check_sub_test_lib_test git-skip-tests-several <<-\\EOF
356 > ok 1 - passing test #1
357 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
358 > ok 3 - passing test #3
359 > ok 4 - passing test #4
360 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
361 > ok 6 - passing test #6
362 > # passed all 6 test(s)
368 test_expect_success
'GIT_SKIP_TESTS sh pattern' "
370 GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS &&
371 run_sub_test_lib_test git-skip-tests-sh-pattern \
372 'GIT_SKIP_TESTS sh pattern' <<-\\EOF &&
375 test_expect_success \"passing test #\$i\" 'true'
379 check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF
380 > ok 1 - passing test #1
381 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
382 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
383 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
384 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
385 > ok 6 - passing test #6
386 > # passed all 6 test(s)
392 test_expect_success
'--run basic' "
393 run_sub_test_lib_test run-basic \
394 '--run basic' --run='1 3 5' <<-\\EOF &&
397 test_expect_success \"passing test #\$i\" 'true'
401 check_sub_test_lib_test run-basic <<-\\EOF
402 > ok 1 - passing test #1
403 > ok 2 # skip passing test #2 (--run)
404 > ok 3 - passing test #3
405 > ok 4 # skip passing test #4 (--run)
406 > ok 5 - passing test #5
407 > ok 6 # skip passing test #6 (--run)
408 > # passed all 6 test(s)
413 test_expect_success
'--run with a range' "
414 run_sub_test_lib_test run-range \
415 '--run with a range' --run='1-3' <<-\\EOF &&
418 test_expect_success \"passing test #\$i\" 'true'
422 check_sub_test_lib_test run-range <<-\\EOF
423 > ok 1 - passing test #1
424 > ok 2 - passing test #2
425 > ok 3 - passing test #3
426 > ok 4 # skip passing test #4 (--run)
427 > ok 5 # skip passing test #5 (--run)
428 > ok 6 # skip passing test #6 (--run)
429 > # passed all 6 test(s)
434 test_expect_success
'--run with two ranges' "
435 run_sub_test_lib_test run-two-ranges \
436 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
439 test_expect_success \"passing test #\$i\" 'true'
443 check_sub_test_lib_test run-two-ranges <<-\\EOF
444 > ok 1 - passing test #1
445 > ok 2 - passing test #2
446 > ok 3 # skip passing test #3 (--run)
447 > ok 4 # skip passing test #4 (--run)
448 > ok 5 - passing test #5
449 > ok 6 - passing test #6
450 > # passed all 6 test(s)
455 test_expect_success
'--run with a left open range' "
456 run_sub_test_lib_test run-left-open-range \
457 '--run with a left open range' --run='-3' <<-\\EOF &&
460 test_expect_success \"passing test #\$i\" 'true'
464 check_sub_test_lib_test run-left-open-range <<-\\EOF
465 > ok 1 - passing test #1
466 > ok 2 - passing test #2
467 > ok 3 - passing test #3
468 > ok 4 # skip passing test #4 (--run)
469 > ok 5 # skip passing test #5 (--run)
470 > ok 6 # skip passing test #6 (--run)
471 > # passed all 6 test(s)
476 test_expect_success
'--run with a right open range' "
477 run_sub_test_lib_test run-right-open-range \
478 '--run with a right open range' --run='4-' <<-\\EOF &&
481 test_expect_success \"passing test #\$i\" 'true'
485 check_sub_test_lib_test run-right-open-range <<-\\EOF
486 > ok 1 # skip passing test #1 (--run)
487 > ok 2 # skip passing test #2 (--run)
488 > ok 3 # skip passing test #3 (--run)
489 > ok 4 - passing test #4
490 > ok 5 - passing test #5
491 > ok 6 - passing test #6
492 > # passed all 6 test(s)
497 test_expect_success
'--run with basic negation' "
498 run_sub_test_lib_test run-basic-neg \
499 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
502 test_expect_success \"passing test #\$i\" 'true'
506 check_sub_test_lib_test run-basic-neg <<-\\EOF
507 > ok 1 - passing test #1
508 > ok 2 - passing test #2
509 > ok 3 # skip passing test #3 (--run)
510 > ok 4 - passing test #4
511 > ok 5 - passing test #5
512 > ok 6 - passing test #6
513 > # passed all 6 test(s)
518 test_expect_success
'--run with two negations' "
519 run_sub_test_lib_test run-two-neg \
520 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
523 test_expect_success \"passing test #\$i\" 'true'
527 check_sub_test_lib_test run-two-neg <<-\\EOF
528 > ok 1 - passing test #1
529 > ok 2 - passing test #2
530 > ok 3 # skip passing test #3 (--run)
531 > ok 4 - passing test #4
532 > ok 5 - passing test #5
533 > ok 6 # skip passing test #6 (--run)
534 > # passed all 6 test(s)
539 test_expect_success
'--run a range and negation' "
540 run_sub_test_lib_test run-range-and-neg \
541 '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
544 test_expect_success \"passing test #\$i\" 'true'
548 check_sub_test_lib_test run-range-and-neg <<-\\EOF
549 > ok 1 - passing test #1
550 > ok 2 # skip passing test #2 (--run)
551 > ok 3 - passing test #3
552 > ok 4 - passing test #4
553 > ok 5 # skip passing test #5 (--run)
554 > ok 6 # skip passing test #6 (--run)
555 > # passed all 6 test(s)
560 test_expect_success
'--run range negation' "
561 run_sub_test_lib_test run-range-neg \
562 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
565 test_expect_success \"passing test #\$i\" 'true'
569 check_sub_test_lib_test run-range-neg <<-\\EOF
570 > ok 1 # skip passing test #1 (--run)
571 > ok 2 # skip passing test #2 (--run)
572 > ok 3 # skip passing test #3 (--run)
573 > ok 4 - passing test #4
574 > ok 5 - passing test #5
575 > ok 6 - passing test #6
576 > # passed all 6 test(s)
581 test_expect_success
'--run include, exclude and include' "
582 run_sub_test_lib_test run-inc-neg-inc \
583 '--run include, exclude and include' \
584 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
587 test_expect_success \"passing test #\$i\" 'true'
591 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
592 > ok 1 # skip passing test #1 (--run)
593 > ok 2 - passing test #2
594 > ok 3 # skip passing test #3 (--run)
595 > ok 4 - passing test #4
596 > ok 5 - passing test #5
597 > ok 6 # skip passing test #6 (--run)
598 > # passed all 6 test(s)
603 test_expect_success
'--run include, exclude and include, comma separated' "
604 run_sub_test_lib_test run-inc-neg-inc-comma \
605 '--run include, exclude and include, comma separated' \
606 --run=1-5,\!1-3,2 <<-\\EOF &&
609 test_expect_success \"passing test #\$i\" 'true'
613 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
614 > ok 1 # skip passing test #1 (--run)
615 > ok 2 - passing test #2
616 > ok 3 # skip passing test #3 (--run)
617 > ok 4 - passing test #4
618 > ok 5 - passing test #5
619 > ok 6 # skip passing test #6 (--run)
620 > # passed all 6 test(s)
625 test_expect_success
'--run exclude and include' "
626 run_sub_test_lib_test run-neg-inc \
627 '--run exclude and include' \
628 --run='"'!3- 5'"' <<-\\EOF &&
631 test_expect_success \"passing test #\$i\" 'true'
635 check_sub_test_lib_test run-neg-inc <<-\\EOF
636 > ok 1 - passing test #1
637 > ok 2 - passing test #2
638 > ok 3 # skip passing test #3 (--run)
639 > ok 4 # skip passing test #4 (--run)
640 > ok 5 - passing test #5
641 > ok 6 # skip passing test #6 (--run)
642 > # passed all 6 test(s)
647 test_expect_success
'--run empty selectors' "
648 run_sub_test_lib_test run-empty-sel \
649 '--run empty selectors' \
650 --run='1,,3,,,5' <<-\\EOF &&
653 test_expect_success \"passing test #\$i\" 'true'
657 check_sub_test_lib_test run-empty-sel <<-\\EOF
658 > ok 1 - passing test #1
659 > ok 2 # skip passing test #2 (--run)
660 > ok 3 - passing test #3
661 > ok 4 # skip passing test #4 (--run)
662 > ok 5 - passing test #5
663 > ok 6 # skip passing test #6 (--run)
664 > # passed all 6 test(s)
669 test_expect_success
'--run invalid range start' "
670 run_sub_test_lib_test_err run-inv-range-start \
671 '--run invalid range start' \
672 --run='a-5' <<-\\EOF &&
673 test_expect_success \"passing test #1\" 'true'
676 check_sub_test_lib_test_err run-inv-range-start \
677 <<-\\EOF_OUT 3<<-\\EOF_ERR
678 > FATAL: Unexpected exit with code 1
680 > error: --run: invalid non-numeric in range start: 'a-5'
684 test_expect_success
'--run invalid range end' "
685 run_sub_test_lib_test_err run-inv-range-end \
686 '--run invalid range end' \
687 --run='1-z' <<-\\EOF &&
688 test_expect_success \"passing test #1\" 'true'
691 check_sub_test_lib_test_err run-inv-range-end \
692 <<-\\EOF_OUT 3<<-\\EOF_ERR
693 > FATAL: Unexpected exit with code 1
695 > error: --run: invalid non-numeric in range end: '1-z'
699 test_expect_success
'--run invalid selector' "
700 run_sub_test_lib_test_err run-inv-selector \
701 '--run invalid selector' \
702 --run='1?' <<-\\EOF &&
703 test_expect_success \"passing test #1\" 'true'
706 check_sub_test_lib_test_err run-inv-selector \
707 <<-\\EOF_OUT 3<<-\\EOF_ERR
708 > FATAL: Unexpected exit with code 1
710 > error: --run: invalid non-numeric in test selector: '1?'
715 test_set_prereq HAVEIT
717 test_expect_success HAVEIT
'test runs if prerequisite is satisfied' '
718 test_have_prereq HAVEIT &&
722 test_expect_success DONTHAVEIT
'unmet prerequisite causes test to be skipped' '
725 if test $haveit$donthaveit != yesyes
727 say
"bug in test framework: prerequisite tags do not work reliably"
731 test_set_prereq HAVETHIS
733 test_expect_success HAVETHIS
,HAVEIT
'test runs if prerequisites are satisfied' '
734 test_have_prereq HAVEIT &&
735 test_have_prereq HAVETHIS &&
739 test_expect_success HAVEIT
,DONTHAVEIT
'unmet prerequisites causes test to be skipped' '
743 test_expect_success DONTHAVEIT
,HAVEIT
'unmet prerequisites causes test to be skipped' '
746 if test $haveit$donthaveit$donthaveiteither != yesyesyes
748 say
"bug in test framework: multiple prerequisite tags do not work reliably"
752 test_lazy_prereq LAZY_TRUE true
754 test_expect_success LAZY_TRUE
'test runs if lazy prereq is satisfied' '
758 test_expect_success
!LAZY_TRUE
'missing lazy prereqs skip tests' '
762 if test "$havetrue$donthavetrue" != yesyes
764 say
'bug in test framework: lazy prerequisites do not work'
768 test_lazy_prereq LAZY_FALSE false
770 test_expect_success
!LAZY_FALSE
'negative lazy prereqs checked' '
774 test_expect_success LAZY_FALSE
'missing negative lazy prereqs will skip' '
778 if test "$nothavefalse$havefalse" != yesyes
780 say
'bug in test framework: negative lazy prerequisites do not work'
785 test_expect_success
'tests clean up after themselves' '
786 test_when_finished clean=yes
789 if test $clean != yes
791 say
"bug in test framework: basic cleanup command does not work reliably"
795 test_expect_success
'tests clean up even on failures' "
796 test_must_fail run_sub_test_lib_test \
797 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
798 test_expect_success 'tests clean up even after a failure' '
799 touch clean-after-failure &&
800 test_when_finished rm clean-after-failure &&
803 test_expect_success 'failure to clean up causes the test to fail' '
804 test_when_finished \"(exit 2)\"
808 check_sub_test_lib_test failing-cleanup <<-\\EOF
809 > not ok 1 - tests clean up even after a failure
811 > # touch clean-after-failure &&
812 > # test_when_finished rm clean-after-failure &&
815 > not ok 2 - failure to clean up causes the test to fail
817 > # test_when_finished \"(exit 2)\"
819 > # failed 2 among 2 test(s)
824 test_expect_success
'test_oid setup' '
828 test_expect_success
'test_oid provides sane info by default' '
829 test_oid zero >actual &&
830 grep "^00*\$" actual &&
831 rawsz="$(test_oid rawsz)" &&
832 hexsz="$(test_oid hexsz)" &&
833 test "$hexsz" -eq $(wc -c <actual) &&
834 test $(( $rawsz * 2)) -eq "$hexsz"
837 test_expect_success
'test_oid can look up data for SHA-1' '
838 test_when_finished "test_detect_hash" &&
839 test_set_hash sha1 &&
840 test_oid zero >actual &&
841 grep "^00*\$" actual &&
842 rawsz="$(test_oid rawsz)" &&
843 hexsz="$(test_oid hexsz)" &&
844 test $(wc -c <actual) -eq 40 &&
845 test "$rawsz" -eq 20 &&
849 test_expect_success
'test_oid can look up data for SHA-256' '
850 test_when_finished "test_detect_hash" &&
851 test_set_hash sha256 &&
852 test_oid zero >actual &&
853 grep "^00*\$" actual &&
854 rawsz="$(test_oid rawsz)" &&
855 hexsz="$(test_oid hexsz)" &&
856 test $(wc -c <actual) -eq 64 &&
857 test "$rawsz" -eq 32 &&
861 ################################################################
862 # Basics of the basics
864 test_oid_cache
<<\EOF
865 path0f sha1
:f87290f8eb2cbbea7857214459a0739927eab154
866 path0f sha256
:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
868 path0s sha1
:15a98433ae33114b085f3eb3bb03b832b3180a01
869 path0s sha256
:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
871 path2f sha1
:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
872 path2f sha256
:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
874 path2s sha1
:d8ce161addc5173867a3c3c730924388daedbc38
875 path2s sha256
:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
877 path2d sha1
:58a09c23e2ca152193f2786e06986b7b6712bdbe
878 path2d sha256
:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
880 path3f sha1
:0aa34cae68d0878578ad119c86ca2b5ed5b28376
881 path3f sha256
:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
883 path3s sha1
:8599103969b43aff7e430efea79ca4636466794f
884 path3s sha256
:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
886 path3d sha1
:21ae8269cacbe57ae09138dcc3a2887f904d02b3
887 path3d sha256
:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
889 subp3f sha1
:00fb5908cb97c2564a9783c0c64087333b3b464f
890 subp3f sha256
:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
892 subp3s sha1
:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
893 subp3s sha256
:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
895 subp3d sha1
:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
896 subp3d sha256
:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
898 root sha1
:087704a96baf1c2d1c869a8b084481e121c88b5b
899 root sha256
:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
901 simpletree sha1
:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
902 simpletree sha256
:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
905 # updating a new file without --add should fail.
906 test_expect_success
'git update-index without --add should fail adding' '
907 test_must_fail git update-index should-be-empty
910 # and with --add it should succeed, even if it is empty (it used to fail).
911 test_expect_success
'git update-index with --add should succeed' '
912 git update-index --add should-be-empty
915 test_expect_success
'writing tree out with git write-tree' '
916 tree=$(git write-tree)
919 # we know the shape and contents of the tree and know the object ID for it.
920 test_expect_success
'validate object ID of a known tree' '
921 test "$tree" = "$(test_oid simpletree)"
925 test_expect_success
'git update-index without --remove should fail removing' '
926 rm -f should-be-empty full-of-directories &&
927 test_must_fail git update-index should-be-empty
930 test_expect_success
'git update-index with --remove should be able to remove' '
931 git update-index --remove should-be-empty
934 # Empty tree can be written with recent write-tree.
935 test_expect_success
'git write-tree should be able to write an empty tree' '
936 tree=$(git write-tree)
939 test_expect_success
'validate object ID of a known tree' '
940 test "$tree" = $EMPTY_TREE
943 # Various types of objects
945 test_expect_success
'adding various types of objects with git update-index --add' '
946 mkdir path2 path3 path3/subp3 &&
947 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
951 echo "hello $p" >$p || exit 1
952 test_ln_s_add "hello $p" ${p}sym || exit 1
955 find path* ! -type d -print | xargs git update-index --add
958 # Show them and see that matches what we expect.
959 test_expect_success
'showing stage with git ls-files --stage' '
960 git ls-files --stage >current
963 test_expect_success
'validate git ls-files output for a known tree' '
964 cat >expected <<-EOF &&
965 100644 $(test_oid path0f) 0 path0
966 120000 $(test_oid path0s) 0 path0sym
967 100644 $(test_oid path2f) 0 path2/file2
968 120000 $(test_oid path2s) 0 path2/file2sym
969 100644 $(test_oid path3f) 0 path3/file3
970 120000 $(test_oid path3s) 0 path3/file3sym
971 100644 $(test_oid subp3f) 0 path3/subp3/file3
972 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
974 test_cmp expected current
977 test_expect_success
'writing tree out with git write-tree' '
978 tree=$(git write-tree)
981 test_expect_success
'validate object ID for a known tree' '
982 test "$tree" = "$(test_oid root)"
985 test_expect_success
'showing tree with git ls-tree' '
986 git ls-tree $tree >current
989 test_expect_success
'git ls-tree output for a known tree' '
990 cat >expected <<-EOF &&
991 100644 blob $(test_oid path0f) path0
992 120000 blob $(test_oid path0s) path0sym
993 040000 tree $(test_oid path2d) path2
994 040000 tree $(test_oid path3d) path3
996 test_cmp expected current
999 # This changed in ls-tree pathspec change -- recursive does
1000 # not show tree nodes anymore.
1001 test_expect_success
'showing tree with git ls-tree -r' '
1002 git ls-tree -r $tree >current
1005 test_expect_success
'git ls-tree -r output for a known tree' '
1006 cat >expected <<-EOF &&
1007 100644 blob $(test_oid path0f) path0
1008 120000 blob $(test_oid path0s) path0sym
1009 100644 blob $(test_oid path2f) path2/file2
1010 120000 blob $(test_oid path2s) path2/file2sym
1011 100644 blob $(test_oid path3f) path3/file3
1012 120000 blob $(test_oid path3s) path3/file3sym
1013 100644 blob $(test_oid subp3f) path3/subp3/file3
1014 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1016 test_cmp expected current
1019 # But with -r -t we can have both.
1020 test_expect_success
'showing tree with git ls-tree -r -t' '
1021 git ls-tree -r -t $tree >current
1024 test_expect_success
'git ls-tree -r output for a known tree' '
1025 cat >expected <<-EOF &&
1026 100644 blob $(test_oid path0f) path0
1027 120000 blob $(test_oid path0s) path0sym
1028 040000 tree $(test_oid path2d) path2
1029 100644 blob $(test_oid path2f) path2/file2
1030 120000 blob $(test_oid path2s) path2/file2sym
1031 040000 tree $(test_oid path3d) path3
1032 100644 blob $(test_oid path3f) path3/file3
1033 120000 blob $(test_oid path3s) path3/file3sym
1034 040000 tree $(test_oid subp3d) path3/subp3
1035 100644 blob $(test_oid subp3f) path3/subp3/file3
1036 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1038 test_cmp expected current
1041 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1042 ptree=$(git write-tree --prefix=path3)
1045 test_expect_success
'validate object ID for a known tree' '
1046 test "$ptree" = $(test_oid path3d)
1049 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1050 ptree=$(git write-tree --prefix=path3/subp3)
1053 test_expect_success
'validate object ID for a known tree' '
1054 test "$ptree" = $(test_oid subp3d)
1057 test_expect_success
'put invalid objects into the index' '
1059 suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1060 cat >badobjects <<-EOF &&
1061 100644 blob $(test_oid 001) dir/file1
1062 100644 blob $(test_oid 002) dir/file2
1063 100644 blob $(test_oid 003) dir/file3
1064 100644 blob $(test_oid 004) dir/file4
1065 100644 blob $(test_oid 005) dir/file5
1067 git update-index --index-info <badobjects
1070 test_expect_success
'writing this tree without --missing-ok' '
1071 test_must_fail git write-tree
1074 test_expect_success
'writing this tree with --missing-ok' '
1075 git write-tree --missing-ok
1079 ################################################################
1080 test_expect_success
'git read-tree followed by write-tree should be idempotent' '
1082 git read-tree $tree &&
1083 test -f .git/index &&
1084 newtree=$(git write-tree) &&
1085 test "$newtree" = "$tree"
1088 test_expect_success
'validate git diff-files output for a know cache/work tree state' '
1089 cat >expected <<EOF &&
1090 :100644 100644 $(test_oid path0f) $ZERO_OID M path0
1091 :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1092 :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1093 :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1094 :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1095 :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1096 :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1097 :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
1099 git diff-files >current &&
1100 test_cmp expected current
1103 test_expect_success
'git update-index --refresh should succeed' '
1104 git update-index --refresh
1107 test_expect_success
'no diff after checkout and git update-index --refresh' '
1108 git diff-files >current &&
1109 cmp -s current /dev/null
1112 ################################################################
1115 test_expect_success
'git commit-tree records the correct tree in a commit' '
1116 commit0=$(echo NO | git commit-tree $P) &&
1117 tree=$(git show --pretty=raw $commit0 |
1118 sed -n -e "s/^tree //p" -e "/^author /q") &&
1119 test "z$tree" = "z$P"
1122 test_expect_success
'git commit-tree records the correct parent in a commit' '
1123 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1124 parent=$(git show --pretty=raw $commit1 |
1125 sed -n -e "s/^parent //p" -e "/^author /q") &&
1126 test "z$commit0" = "z$parent"
1129 test_expect_success
'git commit-tree omits duplicated parent in a commit' '
1130 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1131 parent=$(git show --pretty=raw $commit2 |
1132 sed -n -e "s/^parent //p" -e "/^author /q" |
1134 test "z$commit0" = "z$parent" &&
1135 numparent=$(git show --pretty=raw $commit2 |
1136 sed -n -e "s/^parent //p" -e "/^author /q" |
1141 test_expect_success
'update-index D/F conflict' '
1145 git update-index --add --replace path2 path0/file2 &&
1146 numpath0=$(git ls-files path0 | wc -l) &&
1150 test_expect_success
'very long name in the index handled sanely' '
1153 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1154 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1155 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1159 git update-index --add path4 &&
1161 git ls-files -s path4 |
1165 ) | git update-index --index-info &&
1166 len=$(git ls-files "a*" | wc -c) &&