3 # Copyright (C) 2005 Junio C Hamano
4 # Copyright (C) 2016 Kyle J. McKay
8 test_description
='Test the very basics part #1.
10 The rest of the test suite does not check the basic operation of git
11 plumbing commands to work very carefully. Their job is to concentrate
12 on tricky features that caused bugs in the past to detect regression.
14 This test runs very basic features, like registering things in cache,
17 Note that this test *deliberately* hard-codes many expected object
18 IDs. When object ID computation changes, like in the previous case of
19 swapping compression and hashing order, the person who is making the
20 modification *should* take notice and update the test vectors here.
25 ################################################################
26 # git init has been done in an empty repository.
27 # make sure it is empty.
29 test_expect_success
'.git/objects should be empty after git init in an empty repo' '
30 find .git/objects -type f -print >should-be-empty &&
31 test_line_count = 0 should-be-empty
34 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
35 # 3 is counting "objects" itself
36 test_expect_success
'.git/objects should have 3 subdirectories' '
37 find .git/objects -type d -print >full-of-directories &&
38 test_line_count = 3 full-of-directories
41 ################################################################
43 test_expect_success
'success is reported like this' '
47 _run_sub_test_lib_test_common
() {
48 neg
="$1" name
="$2" descr
="$3" # stdin is the body of the test code
52 # Pretend we're not running under a test harness, whether we
53 # are or not. The test-lib output depends on the setting of
54 # this variable, so we need a stable setting under which to run
56 sane_unset HARNESS_ACTIVE
&&
58 ln -s "$TESTLIB_DIRECTORY/test-lib.sh" .
&&
59 cat >"$name.sh" <<-EOF &&
62 test_description='$descr (run in sub test-lib)
64 This is run in a sub test-lib so that we do not get incorrect
68 # Unset LINENO as it's not universally supported and we do not
69 # want to have to count lines to generate the expected output!
76 chmod +x
"$name.sh" &&
77 TEST_OUTPUT_DIRECTORY
=$
(pwd) &&
78 export TEST_OUTPUT_DIRECTORY
&&
81 .
/"$name.sh" "$@" >out
2>err
83 ! .
/"$name.sh" "$@" >out
2>err
88 run_sub_test_lib_test
() {
89 _run_sub_test_lib_test_common
'' "$@"
92 run_sub_test_lib_test_err
() {
93 _run_sub_test_lib_test_common
'!' "$@"
96 check_sub_test_lib_test
() {
97 name
="$1" # stdin is the expected output from the test
101 sed -e 's/^> //' -e 's/Z$//' >expect
&&
106 check_sub_test_lib_test_err
() {
107 name
="$1" # stdin is the expected output from the test
108 # expected error output is in descriptior 3
111 sed -e 's/^> //' -e 's/Z$//' >expect.out
&&
112 test_cmp expect.out out
&&
113 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err
&&
114 test_cmp expect.err err
118 test_expect_success
'pretend we have a fully passing test suite' "
119 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
122 test_expect_success \"passing test #\$i\" 'true'
126 check_sub_test_lib_test full-pass <<-\\EOF
127 > ok 1 - passing test #1
128 > ok 2 - passing test #2
129 > ok 3 - passing test #3
130 > # passed all 3 test(s)
135 test_expect_success
'pretend we have a partially passing test suite' "
136 test_must_fail run_sub_test_lib_test \
137 partial-pass '2/3 tests passing' <<-\\EOF &&
138 test_expect_success 'passing test #1' 'true'
139 test_expect_success 'failing test #2' 'false'
140 test_expect_success 'passing test #3' 'true'
143 check_sub_test_lib_test partial-pass <<-\\EOF
144 > ok 1 - passing test #1
145 > not ok 2 - failing test #2
146 # failed: partial-pass.sh
150 > ok 3 - passing test #3
151 > # failed 1 among 3 test(s)
156 test_expect_success
'pretend we have a known breakage' "
157 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
158 test_expect_success 'passing test' 'true'
159 test_expect_failure 'pretend we have a known breakage' 'false'
162 check_sub_test_lib_test failing-todo <<-\\EOF
163 > ok 1 - passing test
164 > not ok 2 - pretend we have a known breakage # TODO known breakage
165 > # still have 1 known breakage(s)
166 > # passed all remaining 1 test(s)
171 test_expect_success
'pretend we have fixed a known breakage' "
172 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
173 test_expect_failure 'pretend we have fixed a known breakage' 'true'
176 check_sub_test_lib_test passing-todo <<-\\EOF
177 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
178 > # 1 known breakage(s) vanished; please update test(s)
183 test_expect_success
'pretend we have fixed one of two known breakages (run in sub test-lib)' "
184 run_sub_test_lib_test partially-passing-todos \
185 '2 TODO tests, one passing' <<-\\EOF &&
186 test_expect_failure 'pretend we have a known breakage' 'false'
187 test_expect_success 'pretend we have a passing test' 'true'
188 test_expect_failure 'pretend we have fixed another known breakage' 'true'
191 check_sub_test_lib_test partially-passing-todos <<-\\EOF
192 > not ok 1 - pretend we have a known breakage # TODO known breakage
193 > ok 2 - pretend we have a passing test
194 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
195 > # 1 known breakage(s) vanished; please update test(s)
196 > # still have 1 known breakage(s)
197 > # passed all remaining 1 test(s)
202 test_expect_success
'pretend we have a pass, fail, and known breakage' "
203 test_must_fail run_sub_test_lib_test \
204 mixed-results1 'mixed results #1' <<-\\EOF &&
205 test_expect_success 'passing test' 'true'
206 test_expect_success 'failing test' 'false'
207 test_expect_failure 'pretend we have a known breakage' 'false'
210 check_sub_test_lib_test mixed-results1 <<-\\EOF
211 > ok 1 - passing test
212 > not ok 2 - failing test
213 > # failed: mixed-results1.sh
217 > not ok 3 - pretend we have a known breakage # TODO known breakage
218 > # still have 1 known breakage(s)
219 > # failed 1 among remaining 2 test(s)
224 test_expect_success
'pretend we have a mix of all possible results' "
225 test_must_fail run_sub_test_lib_test \
226 mixed-results2 'mixed results #2' <<-\\EOF &&
227 test_expect_success 'passing test' 'true'
228 test_expect_success 'passing test' 'true'
229 test_expect_success 'passing test' 'true'
230 test_expect_success 'passing test' 'true'
231 test_expect_success 'failing test' 'false'
232 test_expect_success 'failing test' 'false'
233 test_expect_success 'failing test' 'false'
234 test_expect_failure 'pretend we have a known breakage' 'false'
235 test_expect_failure 'pretend we have a known breakage' 'false'
236 test_expect_failure 'pretend we have fixed a known breakage' 'true'
239 check_sub_test_lib_test mixed-results2 <<-\\EOF
240 > ok 1 - passing test
241 > ok 2 - passing test
242 > ok 3 - passing test
243 > ok 4 - passing test
244 > not ok 5 - failing test
245 > # failed: mixed-results2.sh
249 > not ok 6 - failing test
250 > # failed: mixed-results2.sh
254 > not ok 7 - failing test
255 > # failed: mixed-results2.sh
259 > not ok 8 - pretend we have a known breakage # TODO known breakage
260 > not ok 9 - pretend we have a known breakage # TODO known breakage
261 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
262 > # 1 known breakage(s) vanished; please update test(s)
263 > # still have 2 known breakage(s)
264 > # failed 3 among remaining 7 test(s)
269 test_expect_success
'test --verbose' '
270 test_must_fail run_sub_test_lib_test \
271 test-verbose "test verbose" --verbose <<-\EOF &&
272 test_expect_success "passing test" true
273 test_expect_success "test with output" "echo foo"
274 test_expect_success "failing test" false
277 mv test-verbose/out test-verbose/out+ &&
278 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
279 check_sub_test_lib_test test-verbose <<-\EOF
280 > expecting success: true
281 > ok 1 - passing test
283 > expecting success: echo foo
285 > ok 2 - test with output
287 > expecting success: false
288 > not ok 3 - failing test
289 > # failed: test-verbose.sh
294 > # failed 1 among 3 test(s)
299 test_expect_success
'test --verbose-only' '
300 test_must_fail run_sub_test_lib_test \
301 test-verbose-only-2 "test verbose-only=2" \
302 --verbose-only=2 <<-\EOF &&
303 test_expect_success "passing test" true
304 test_expect_success "test with output" "echo foo"
305 test_expect_success "failing test" false
308 check_sub_test_lib_test test-verbose-only-2 <<-\EOF
309 > ok 1 - passing test
311 > expecting success: echo foo
313 > ok 2 - test with output
315 > not ok 3 - failing test
316 > # failed: test-verbose-only-2.sh
320 > # failed 1 among 3 test(s)
325 test_expect_success
'TESTLIB_SKIP_TESTS' "
327 TESTLIB_SKIP_TESTS='testlib.2' && export TESTLIB_SKIP_TESTS &&
328 run_sub_test_lib_test testlib-skip-tests-basic \
329 'TESTLIB_SKIP_TESTS' <<-\\EOF &&
332 test_expect_success \"passing test #\$i\" 'true'
336 check_sub_test_lib_test testlib-skip-tests-basic <<-\\EOF
337 > ok 1 - passing test #1
338 > ok 2 # skip passing test #2 (TESTLIB_SKIP_TESTS)
339 > ok 3 - passing test #3
340 > # passed all 3 test(s)
346 test_expect_success
'TESTLIB_SKIP_TESTS several tests' "
348 TESTLIB_SKIP_TESTS='testlib.2 testlib.5' && export TESTLIB_SKIP_TESTS &&
349 run_sub_test_lib_test testlib-skip-tests-several \
350 'TESTLIB_SKIP_TESTS several tests' <<-\\EOF &&
353 test_expect_success \"passing test #\$i\" 'true'
357 check_sub_test_lib_test testlib-skip-tests-several <<-\\EOF
358 > ok 1 - passing test #1
359 > ok 2 # skip passing test #2 (TESTLIB_SKIP_TESTS)
360 > ok 3 - passing test #3
361 > ok 4 - passing test #4
362 > ok 5 # skip passing test #5 (TESTLIB_SKIP_TESTS)
363 > ok 6 - passing test #6
364 > # passed all 6 test(s)
370 test_expect_success
'TESTLIB_SKIP_TESTS sh pattern' "
372 TESTLIB_SKIP_TESTS='testlib.[2-5]' && export TESTLIB_SKIP_TESTS &&
373 run_sub_test_lib_test testlib-skip-tests-sh-pattern \
374 'TESTLIB_SKIP_TESTS sh pattern' <<-\\EOF &&
377 test_expect_success \"passing test #\$i\" 'true'
381 check_sub_test_lib_test testlib-skip-tests-sh-pattern <<-\\EOF
382 > ok 1 - passing test #1
383 > ok 2 # skip passing test #2 (TESTLIB_SKIP_TESTS)
384 > ok 3 # skip passing test #3 (TESTLIB_SKIP_TESTS)
385 > ok 4 # skip passing test #4 (TESTLIB_SKIP_TESTS)
386 > ok 5 # skip passing test #5 (TESTLIB_SKIP_TESTS)
387 > ok 6 - passing test #6
388 > # passed all 6 test(s)
394 test_expect_success
'--run basic' "
395 run_sub_test_lib_test run-basic \
396 '--run basic' --run='1 3 5' <<-\\EOF &&
399 test_expect_success \"passing test #\$i\" 'true'
403 check_sub_test_lib_test run-basic <<-\\EOF
404 > ok 1 - passing test #1
405 > ok 2 # skip passing test #2 (--run)
406 > ok 3 - passing test #3
407 > ok 4 # skip passing test #4 (--run)
408 > ok 5 - passing test #5
409 > ok 6 # skip passing test #6 (--run)
410 > # passed all 6 test(s)
415 test_expect_success
'--run with a range' "
416 run_sub_test_lib_test run-range \
417 '--run with a range' --run='1-3' <<-\\EOF &&
420 test_expect_success \"passing test #\$i\" 'true'
424 check_sub_test_lib_test run-range <<-\\EOF
425 > ok 1 - passing test #1
426 > ok 2 - passing test #2
427 > ok 3 - passing test #3
428 > ok 4 # skip passing test #4 (--run)
429 > ok 5 # skip passing test #5 (--run)
430 > ok 6 # skip passing test #6 (--run)
431 > # passed all 6 test(s)
436 test_expect_success
'--run with two ranges' "
437 run_sub_test_lib_test run-two-ranges \
438 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
441 test_expect_success \"passing test #\$i\" 'true'
445 check_sub_test_lib_test run-two-ranges <<-\\EOF
446 > ok 1 - passing test #1
447 > ok 2 - passing test #2
448 > ok 3 # skip passing test #3 (--run)
449 > ok 4 # skip passing test #4 (--run)
450 > ok 5 - passing test #5
451 > ok 6 - passing test #6
452 > # passed all 6 test(s)
457 test_expect_success
'--run with a left open range' "
458 run_sub_test_lib_test run-left-open-range \
459 '--run with a left open range' --run='-3' <<-\\EOF &&
462 test_expect_success \"passing test #\$i\" 'true'
466 check_sub_test_lib_test run-left-open-range <<-\\EOF
467 > ok 1 - passing test #1
468 > ok 2 - passing test #2
469 > ok 3 - passing test #3
470 > ok 4 # skip passing test #4 (--run)
471 > ok 5 # skip passing test #5 (--run)
472 > ok 6 # skip passing test #6 (--run)
473 > # passed all 6 test(s)
478 test_expect_success
'--run with a right open range' "
479 run_sub_test_lib_test run-right-open-range \
480 '--run with a right open range' --run='4-' <<-\\EOF &&
483 test_expect_success \"passing test #\$i\" 'true'
487 check_sub_test_lib_test run-right-open-range <<-\\EOF
488 > ok 1 # skip passing test #1 (--run)
489 > ok 2 # skip passing test #2 (--run)
490 > ok 3 # skip passing test #3 (--run)
491 > ok 4 - passing test #4
492 > ok 5 - passing test #5
493 > ok 6 - passing test #6
494 > # passed all 6 test(s)
499 test_expect_success
'--run with basic negation' "
500 run_sub_test_lib_test run-basic-neg \
501 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
504 test_expect_success \"passing test #\$i\" 'true'
508 check_sub_test_lib_test run-basic-neg <<-\\EOF
509 > ok 1 - passing test #1
510 > ok 2 - passing test #2
511 > ok 3 # skip passing test #3 (--run)
512 > ok 4 - passing test #4
513 > ok 5 - passing test #5
514 > ok 6 - passing test #6
515 > # passed all 6 test(s)
520 test_expect_success
'--run with two negations' "
521 run_sub_test_lib_test run-two-neg \
522 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
525 test_expect_success \"passing test #\$i\" 'true'
529 check_sub_test_lib_test run-two-neg <<-\\EOF
530 > ok 1 - passing test #1
531 > ok 2 - passing test #2
532 > ok 3 # skip passing test #3 (--run)
533 > ok 4 - passing test #4
534 > ok 5 - passing test #5
535 > ok 6 # skip passing test #6 (--run)
536 > # passed all 6 test(s)
541 test_expect_success
'--run a range and negation' "
542 run_sub_test_lib_test run-range-and-neg \
543 '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
546 test_expect_success \"passing test #\$i\" 'true'
550 check_sub_test_lib_test run-range-and-neg <<-\\EOF
551 > ok 1 - passing test #1
552 > ok 2 # skip passing test #2 (--run)
553 > ok 3 - passing test #3
554 > ok 4 - passing test #4
555 > ok 5 # skip passing test #5 (--run)
556 > ok 6 # skip passing test #6 (--run)
557 > # passed all 6 test(s)
562 test_expect_success
'--run range negation' "
563 run_sub_test_lib_test run-range-neg \
564 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
567 test_expect_success \"passing test #\$i\" 'true'
571 check_sub_test_lib_test run-range-neg <<-\\EOF
572 > ok 1 # skip passing test #1 (--run)
573 > ok 2 # skip passing test #2 (--run)
574 > ok 3 # skip passing test #3 (--run)
575 > ok 4 - passing test #4
576 > ok 5 - passing test #5
577 > ok 6 - passing test #6
578 > # passed all 6 test(s)
583 test_expect_success
'--run include, exclude and include' "
584 run_sub_test_lib_test run-inc-neg-inc \
585 '--run include, exclude and include' \
586 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
589 test_expect_success \"passing test #\$i\" 'true'
593 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
594 > ok 1 # skip passing test #1 (--run)
595 > ok 2 - passing test #2
596 > ok 3 # skip passing test #3 (--run)
597 > ok 4 - passing test #4
598 > ok 5 - passing test #5
599 > ok 6 # skip passing test #6 (--run)
600 > # passed all 6 test(s)
605 test_expect_success
'--run include, exclude and include, comma separated' "
606 run_sub_test_lib_test run-inc-neg-inc-comma \
607 '--run include, exclude and include, comma separated' \
608 --run=1-5,\!1-3,2 <<-\\EOF &&
611 test_expect_success \"passing test #\$i\" 'true'
615 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
616 > ok 1 # skip passing test #1 (--run)
617 > ok 2 - passing test #2
618 > ok 3 # skip passing test #3 (--run)
619 > ok 4 - passing test #4
620 > ok 5 - passing test #5
621 > ok 6 # skip passing test #6 (--run)
622 > # passed all 6 test(s)
627 test_expect_success
'--run exclude and include' "
628 run_sub_test_lib_test run-neg-inc \
629 '--run exclude and include' \
630 --run='"'!3- 5'"' <<-\\EOF &&
633 test_expect_success \"passing test #\$i\" 'true'
637 check_sub_test_lib_test run-neg-inc <<-\\EOF
638 > ok 1 - passing test #1
639 > ok 2 - passing test #2
640 > ok 3 # skip passing test #3 (--run)
641 > ok 4 # skip passing test #4 (--run)
642 > ok 5 - passing test #5
643 > ok 6 # skip passing test #6 (--run)
644 > # passed all 6 test(s)
649 test_expect_success
'--run empty selectors' "
650 run_sub_test_lib_test run-empty-sel \
651 '--run empty selectors' \
652 --run='1,,3,,,5' <<-\\EOF &&
655 test_expect_success \"passing test #\$i\" 'true'
659 check_sub_test_lib_test run-empty-sel <<-\\EOF
660 > ok 1 - passing test #1
661 > ok 2 # skip passing test #2 (--run)
662 > ok 3 - passing test #3
663 > ok 4 # skip passing test #4 (--run)
664 > ok 5 - passing test #5
665 > ok 6 # skip passing test #6 (--run)
666 > # passed all 6 test(s)
671 test_expect_success
'--run invalid range start' "
672 run_sub_test_lib_test_err run-inv-range-start \
673 '--run invalid range start' \
674 --run='a-5' <<-\\EOF &&
675 test_expect_success \"passing test #1\" 'true'
678 check_sub_test_lib_test_err run-inv-range-start \
679 <<-\\EOF_OUT 3<<-\\EOF_ERR
680 > FATAL: Unexpected exit with code 1
682 > error: --run: invalid non-numeric in range start: 'a-5'
686 test_expect_success
'--run invalid range end' "
687 run_sub_test_lib_test_err run-inv-range-end \
688 '--run invalid range end' \
689 --run='1-z' <<-\\EOF &&
690 test_expect_success \"passing test #1\" 'true'
693 check_sub_test_lib_test_err run-inv-range-end \
694 <<-\\EOF_OUT 3<<-\\EOF_ERR
695 > FATAL: Unexpected exit with code 1
697 > error: --run: invalid non-numeric in range end: '1-z'
701 test_expect_success
'--run invalid selector' "
702 run_sub_test_lib_test_err run-inv-selector \
703 '--run invalid selector' \
704 --run='1?' <<-\\EOF &&
705 test_expect_success \"passing test #1\" 'true'
708 check_sub_test_lib_test_err run-inv-selector \
709 <<-\\EOF_OUT 3<<-\\EOF_ERR
710 > FATAL: Unexpected exit with code 1
712 > error: --run: invalid non-numeric in test selector: '1?'
717 test_set_prereq HAVEIT
719 echo "$haveit" >haveit
720 test_expect_success HAVEIT
'test runs if prerequisite is satisfied' '
721 test_have_prereq HAVEIT &&
723 echo "$haveit" >haveit
726 echo "$donthaveit" >donthaveit
727 test_expect_success DONTHAVEIT
'unmet prerequisite causes test to be skipped' '
729 echo "$donthaveit" >donthaveit
731 haveitf
="$(cat haveit)"
732 donthaveitf
="$(cat donthaveit)"
733 if test $haveit$donthaveit != noyes ||
test $haveitf$donthaveitf != yesyes
735 say
"bug in test framework: prerequisite tags do not work reliably"
739 # Stop with the fussing with files
740 TESTLIB_TEST_NO_SUBSHELL
=1
742 test_set_prereq HAVETHIS
744 test_expect_success HAVETHIS
,HAVEIT
'test runs if prerequisites are satisfied' '
745 test_have_prereq HAVEIT &&
746 test_have_prereq HAVETHIS &&
750 test_expect_success HAVEIT
,DONTHAVEIT
'unmet prerequisites causes test to be skipped' '
754 test_expect_success DONTHAVEIT
,HAVEIT
'unmet prerequisites causes test to be skipped' '
757 if test $haveit$donthaveit$donthaveiteither != yesyesyes
759 say
"bug in test framework: multiple prerequisite tags do not work reliably"
763 test_lazy_prereq LAZY_TRUE true
765 test_expect_success LAZY_TRUE
'test runs if lazy prereq is satisfied' '
769 test_expect_success
!LAZY_TRUE
'missing lazy prereqs skip tests' '
773 if test "$havetrue$donthavetrue" != yesyes
775 say
'bug in test framework: lazy prerequisites do not work'
779 test_lazy_prereq LAZY_FALSE false
781 test_expect_success
!LAZY_FALSE
'negative lazy prereqs checked' '
785 test_expect_success LAZY_FALSE
'missing negative lazy prereqs will skip' '
789 if test "$nothavefalse$havefalse" != yesyes
791 say
'bug in test framework: negative lazy prerequisites do not work'
796 test_expect_success
'tests clean up after themselves' '
797 test_when_finished clean=yes
800 if test $clean != yes
802 say
"bug in test framework: basic cleanup command does not work reliably"
806 # Done with the no subshell tests
807 unset TESTLIB_TEST_NO_SUBSHELL
809 test_expect_success
'tests clean up even on failures' "
810 test_must_fail run_sub_test_lib_test \
811 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
812 TESTLIB_TEST_NO_SUBSHELL=1
813 test_expect_success 'tests clean up even after a failure' '
814 touch clean-after-failure &&
815 test_when_finished rm clean-after-failure &&
818 test_expect_success 'failure to clean up causes the test to fail' '
819 test_when_finished \"(exit 2)\"
823 check_sub_test_lib_test failing-cleanup <<-\\EOF
824 > not ok 1 - tests clean up even after a failure
825 > # failed: failing-cleanup.sh
827 > # touch clean-after-failure &&
828 > # test_when_finished rm clean-after-failure &&
831 > not ok 2 - failure to clean up causes the test to fail
832 > # failed: failing-cleanup.sh
834 > # test_when_finished \"(exit 2)\"
836 > # failed 2 among 2 test(s)
841 ################################################################
842 # Basics of the basics
844 # updating a new file without --add should fail.
845 test_expect_success
'git update-index without --add should fail adding' '
846 test_must_fail git update-index should-be-empty
849 # and with --add it should succeed, even if it is empty (it used to fail).
850 test_expect_success
'git update-index with --add should succeed' '
851 git update-index --add should-be-empty
854 TESTLIB_TEST_NO_SUBSHELL
=1
855 test_expect_success
'writing tree out with git write-tree' '
856 tree=$(git write-tree)
858 unset TESTLIB_TEST_NO_SUBSHELL
860 # we know the shape and contents of the tree and know the object ID for it.
861 test_expect_success
'validate object ID of a known tree' '
862 test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
866 test_expect_success
'git update-index without --remove should fail removing' '
867 rm -f should-be-empty full-of-directories &&
868 test_must_fail git update-index should-be-empty
871 test_expect_success
'git update-index with --remove should be able to remove' '
872 git update-index --remove should-be-empty
875 # Empty tree can be written with recent write-tree.
876 TESTLIB_TEST_NO_SUBSHELL
=1
877 test_tolerate_failure
'git write-tree should be able to write an empty tree' '
878 tree=$(git write-tree)
880 unset TESTLIB_TEST_NO_SUBSHELL
884 test_result
='test_expect_success'
886 test_result
='test_tolerate_failure'
888 $test_result 'validate object ID of a known tree' '
889 test "$tree" = $EMPTY_TREE
892 # Various types of objects
894 test_expect_success
'adding various types of objects with git update-index --add' '
895 mkdir path2 path3 path3/subp3 &&
896 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
900 echo "hello $p" >$p || exit 1
901 test_ln_s_add "hello $p" ${p}sym || exit 1
904 find path* ! -type d -print | xargs git update-index --add
907 # Show them and see that matches what we expect.
908 test_expect_success
'showing stage with git ls-files --stage' '
909 git ls-files --stage >current
912 test_expect_success
'validate git ls-files output for a known tree' '
913 cat >expected <<-\EOF &&
914 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
915 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
916 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
917 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
918 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
919 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
920 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
921 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
923 test_cmp expected current
926 TESTLIB_TEST_NO_SUBSHELL
=1
927 test_expect_success
'writing tree out with git write-tree' '
928 tree=$(git write-tree)
930 unset TESTLIB_TEST_NO_SUBSHELL
932 test_expect_success
'validate object ID for a known tree' '
933 test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
936 test_expect_success
'showing tree with git ls-tree' '
937 git ls-tree $tree >current
940 test_expect_success
'git ls-tree output for a known tree' '
941 cat >expected <<-\EOF &&
942 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
943 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
944 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
945 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
947 test_cmp expected current
950 # This changed in ls-tree pathspec change -- recursive does
951 # not show tree nodes anymore.
952 test_expect_success
'showing tree with git ls-tree -r' '
953 git ls-tree -r $tree >current
956 test_expect_success
'git ls-tree -r output for a known tree' '
957 cat >expected <<-\EOF &&
958 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
959 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
960 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
961 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
962 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
963 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
964 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
965 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
967 test_cmp expected current
970 # But with -r -t we can have both.
971 test_expect_success
'showing tree with git ls-tree -r -t' '
972 git ls-tree -r -t $tree >current
975 test_expect_success
'git ls-tree -r output for a known tree' '
976 cat >expected <<-\EOF &&
977 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
978 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
979 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
980 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
981 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
982 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
983 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
984 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
985 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
986 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
987 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
989 test_cmp expected current
992 TESTLIB_TEST_NO_SUBSHELL
=1
993 test_expect_success
'writing partial tree out with git write-tree --prefix' '
994 ptree=$(git write-tree --prefix=path3)
996 unset TESTLIB_TEST_NO_SUBSHELL
998 test_expect_success
'validate object ID for a known tree' '
999 test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
1002 TESTLIB_TEST_NO_SUBSHELL
=1
1003 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1004 ptree=$(git write-tree --prefix=path3/subp3)
1006 unset TESTLIB_TEST_NO_SUBSHELL
1008 test_expect_success
'validate object ID for a known tree' '
1009 test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
1012 test_expect_success
'put invalid objects into the index' '
1014 cat >badobjects <<-\EOF &&
1015 100644 blob 1000000000000000000000000000000000000000 dir/file1
1016 100644 blob 2000000000000000000000000000000000000000 dir/file2
1017 100644 blob 3000000000000000000000000000000000000000 dir/file3
1018 100644 blob 4000000000000000000000000000000000000000 dir/file4
1019 100644 blob 5000000000000000000000000000000000000000 dir/file5
1021 git update-index --index-info <badobjects
1024 test_expect_success
'writing this tree without --missing-ok' '
1025 test_must_fail git write-tree
1028 test_expect_success
'writing this tree with --missing-ok' '
1029 git write-tree --missing-ok
1033 ################################################################
1034 test_expect_success
'git read-tree followed by write-tree should be idempotent' '
1036 git read-tree $tree &&
1037 test -f .git/index &&
1038 newtree=$(git write-tree) &&
1039 test "$newtree" = "$tree"
1042 test_expect_success
'validate git diff-files output for a know cache/work tree state' '
1043 cat >expected <<\EOF &&
1044 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
1045 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
1046 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
1047 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
1048 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
1049 :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
1050 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
1051 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
1053 git diff-files >current &&
1054 test_cmp current expected
1057 test_expect_success
'git update-index --refresh should succeed' '
1058 git update-index --refresh
1061 test_expect_success
'no diff after checkout and git update-index --refresh' '
1062 git diff-files >current &&
1063 cmp -s current /dev/null
1066 ################################################################
1067 P
=087704a96baf1c2d1c869a8b084481e121c88b5b
1069 TESTLIB_TEST_NO_SUBSHELL
=1
1070 test_expect_success
'git commit-tree records the correct tree in a commit' '
1071 commit0=$(echo NO | git commit-tree $P) &&
1072 tree=$(git show --pretty=raw $commit0 |
1073 sed -n -e "s/^tree //p" -e "/^author /q") &&
1074 test "z$tree" = "z$P"
1076 unset TESTLIB_TEST_NO_SUBSHELL
1078 test_expect_success
'git commit-tree records the correct parent in a commit' '
1079 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1080 parent=$(git show --pretty=raw $commit1 |
1081 sed -n -e "s/^parent //p" -e "/^author /q") &&
1082 test "z$commit0" = "z$parent"
1085 test_expect_success
'git commit-tree omits duplicated parent in a commit' '
1086 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1087 parent=$(git show --pretty=raw $commit2 |
1088 sed -n -e "s/^parent //p" -e "/^author /q" |
1090 test "z$commit0" = "z$parent" &&
1091 numparent=$(git show --pretty=raw $commit2 |
1092 sed -n -e "s/^parent //p" -e "/^author /q" |
1097 test_expect_success
'update-index D/F conflict' '
1101 git update-index --add --replace path2 path0/file2 &&
1102 numpath0=$(git ls-files path0 | wc -l) &&
1106 test_expect_success
'very long name in the index handled sanely' '
1109 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1110 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1111 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1115 git update-index --add path4 &&
1117 git ls-files -s path4 |
1121 ) | git update-index --index-info &&
1122 len=$(git ls-files "a*" | wc -c) &&