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.
27 ################################################################
28 # git init has been done in an empty repository.
29 # make sure it is empty.
31 test_expect_success
'.git/objects should be empty after git init in an empty repo' '
32 find .git/objects -type f -print >should-be-empty &&
33 test_line_count = 0 should-be-empty
36 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
37 # 3 is counting "objects" itself
38 test_expect_success
'.git/objects should have 3 subdirectories' '
39 find .git/objects -type d -print >full-of-directories &&
40 test_line_count = 3 full-of-directories
43 ################################################################
45 test_expect_success
'success is reported like this' '
49 _run_sub_test_lib_test_common
() {
50 neg
="$1" name
="$2" descr
="$3" # stdin is the body of the test code
54 # Pretend we're not running under a test harness, whether we
55 # are or not. The test-lib output depends on the setting of
56 # this variable, so we need a stable setting under which to run
58 sane_unset HARNESS_ACTIVE
&&
60 ln -s "$TESTLIB_DIRECTORY/test-lib.sh" .
&&
61 cat >"$name.sh" <<-EOF &&
64 test_description='$descr (run in sub test-lib)
66 This is run in a sub test-lib so that we do not get incorrect
72 # Unset LINENO as it's not universally supported and we do not
73 # want to have to count lines to generate the expected output!
76 # may cause some broken sh implementations to abruptly terminate!
77 # Instead just unalias all to avoid picking up the line numbers
78 # after making sure unalias itself is not a function and
79 # dealing with broken zsh that's missing a proper "unalias -a".
80 { "unset" -f unalias; } >/dev/null 2>&1 || :
81 { "unalias" -a || unalias -m "*"; } >/dev/null 2>&1 || :
85 chmod +x
"$name.sh" &&
86 TEST_OUTPUT_DIRECTORY
=$
(pwd) &&
87 export TEST_OUTPUT_DIRECTORY
&&
90 .
/"$name.sh" "$@" >out
2>err
92 ! .
/"$name.sh" "$@" >out
2>err
97 run_sub_test_lib_test
() {
98 _run_sub_test_lib_test_common
'' "$@"
101 run_sub_test_lib_test_err
() {
102 _run_sub_test_lib_test_common
'!' "$@"
105 check_sub_test_lib_test
() {
106 name
="$1" # stdin is the expected output from the test
110 sed -e 's/^> //' -e 's/Z$//' >expect
&&
115 check_sub_test_lib_test_err
() {
116 name
="$1" # stdin is the expected output from the test
117 # expected error output is in descriptior 3
120 sed -e 's/^> //' -e 's/Z$//' >expect.out
&&
121 test_cmp expect.out out
&&
122 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err
&&
123 test_cmp expect.err err
127 test_expect_success
'pretend we have a fully passing test suite' "
128 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
132 test_expect_success \"passing test #\$i\" 'true'
136 check_sub_test_lib_test full-pass <<-\\EOF
138 > ok 1 - passing test #1
139 > ok 2 - passing test #2
140 > ok 3 - passing test #3
141 > # full passed all 3 test(s)
145 test_expect_success
'pretend we have a partially passing test suite' "
146 test_must_fail run_sub_test_lib_test \
147 partial-pass '2/3 tests passing' <<-\\EOF &&
149 test_expect_success 'passing test #1' 'true'
150 test_expect_success 'failing test #2' 'false'
151 test_expect_success 'passing test #3' 'true'
154 check_sub_test_lib_test partial-pass <<-\\EOF
156 > ok 1 - passing test #1
157 > not ok 2 - failing test #2
158 # failed: partial-pass.sh
162 > ok 3 - passing test #3
163 > # partial failed 1 among 3 test(s)
167 test_expect_success
'pretend we have a known breakage' "
168 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
170 test_expect_success 'passing test' 'true'
171 test_expect_failure 'pretend we have a known breakage' 'false'
174 check_sub_test_lib_test failing-todo <<-\\EOF
176 > ok 1 - passing test
177 > not ok 2 - pretend we have a known breakage # TODO known breakage
178 > # failing still have 1 known breakage(s)
179 > # failing passed all remaining 1 test(s)
183 test_expect_success
'pretend we have fixed a known breakage' "
184 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
186 test_expect_failure 'pretend we have fixed a known breakage' 'true'
189 check_sub_test_lib_test passing-todo <<-\\EOF
191 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
192 > # passing 1 known breakage(s) vanished; please update test(s)
196 test_expect_success
'pretend we have fixed one of two known breakages (run in sub test-lib)' "
197 run_sub_test_lib_test partially-passing-todos \
198 '2 TODO tests, one passing' <<-\\EOF &&
200 test_expect_failure 'pretend we have a known breakage' 'false'
201 test_expect_success 'pretend we have a passing test' 'true'
202 test_expect_failure 'pretend we have fixed another known breakage' 'true'
205 check_sub_test_lib_test partially-passing-todos <<-\\EOF
207 > not ok 1 - pretend we have a known breakage # TODO known breakage
208 > ok 2 - pretend we have a passing test
209 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
210 > # partially 1 known breakage(s) vanished; please update test(s)
211 > # partially still have 1 known breakage(s)
212 > # partially passed all remaining 1 test(s)
216 test_expect_success
'pretend we have a pass, fail, and known breakage' "
217 test_must_fail run_sub_test_lib_test \
218 mixed-results1 'mixed results #1' <<-\\EOF &&
220 test_expect_success 'passing test' 'true'
221 test_expect_success 'failing test' 'false'
222 test_expect_failure 'pretend we have a known breakage' 'false'
225 check_sub_test_lib_test mixed-results1 <<-\\EOF
227 > ok 1 - passing test
228 > not ok 2 - failing test
229 > # failed: mixed-results1.sh
233 > not ok 3 - pretend we have a known breakage # TODO known breakage
234 > # mixed still have 1 known breakage(s)
235 > # mixed failed 1 among remaining 2 test(s)
239 test_expect_success
'pretend we have a mix of all possible results' "
240 test_must_fail run_sub_test_lib_test \
241 mixed-results2 'mixed results #2' <<-\\EOF &&
243 test_expect_success 'passing test' 'true'
244 test_expect_success 'passing test' 'true'
245 test_expect_success 'passing test' 'true'
246 test_expect_success 'passing test' 'true'
247 test_expect_success 'failing test' 'false'
248 test_expect_success 'failing test' 'false'
249 test_expect_success 'failing test' 'false'
250 test_expect_failure 'pretend we have a known breakage' 'false'
251 test_expect_failure 'pretend we have a known breakage' 'false'
252 test_expect_failure 'pretend we have fixed a known breakage' 'true'
255 check_sub_test_lib_test mixed-results2 <<-\\EOF
257 > ok 1 - passing test
258 > ok 2 - passing test
259 > ok 3 - passing test
260 > ok 4 - passing test
261 > not ok 5 - failing test
262 > # failed: mixed-results2.sh
266 > not ok 6 - failing test
267 > # failed: mixed-results2.sh
271 > not ok 7 - failing test
272 > # failed: mixed-results2.sh
276 > not ok 8 - pretend we have a known breakage # TODO known breakage
277 > not ok 9 - pretend we have a known breakage # TODO known breakage
278 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
279 > # mixed 1 known breakage(s) vanished; please update test(s)
280 > # mixed still have 2 known breakage(s)
281 > # mixed failed 3 among remaining 7 test(s)
285 test_expect_success
'test --verbose' '
286 test_must_fail run_sub_test_lib_test \
287 test-verbose "test verbose" --verbose <<-\EOF &&
289 test_expect_success "passing test" true
290 test_expect_success "test with output" "echo foo"
291 test_expect_success "failing test" false
294 mv test-verbose/out test-verbose/out+ &&
295 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
296 check_sub_test_lib_test test-verbose <<-\EOF
298 > expecting success: true
299 > ok 1 - passing test
301 > expecting success: echo foo
303 > ok 2 - test with output
305 > expecting success: false
306 > not ok 3 - failing test
307 > # failed: test-verbose.sh
312 > # test failed 1 among 3 test(s)
316 test_expect_success
'test --verbose-only' '
317 test_must_fail run_sub_test_lib_test \
318 test-verbose-only-2 "test verbose-only=2" \
319 --verbose-only=2 <<-\EOF &&
321 test_expect_success "passing test" true
322 test_expect_success "test with output" "echo foo"
323 test_expect_success "failing test" false
326 check_sub_test_lib_test test-verbose-only-2 <<-\EOF
328 > ok 1 - passing test
330 > expecting success: echo foo
332 > ok 2 - test with output
334 > not ok 3 - failing test
335 > # failed: test-verbose-only-2.sh
339 > # test failed 1 among 3 test(s)
343 test_expect_success
'TESTLIB_SKIP_TESTS' "
345 TESTLIB_SKIP_TESTS='testlib.2' && export TESTLIB_SKIP_TESTS &&
346 run_sub_test_lib_test testlib-skip-tests-basic \
347 'TESTLIB_SKIP_TESTS' <<-\\EOF &&
351 test_expect_success \"passing test #\$i\" 'true'
355 check_sub_test_lib_test testlib-skip-tests-basic <<-\\EOF
357 > ok 1 - passing test #1
358 > ok 2 # skip passing test #2 (TESTLIB_SKIP_TESTS)
359 > ok 3 - passing test #3
360 > # testlib passed all 3 test(s)
365 test_expect_success
'TESTLIB_SKIP_TESTS several tests' "
367 TESTLIB_SKIP_TESTS='testlib.2 testlib.5' && export TESTLIB_SKIP_TESTS &&
368 run_sub_test_lib_test testlib-skip-tests-several \
369 'TESTLIB_SKIP_TESTS several tests' <<-\\EOF &&
373 test_expect_success \"passing test #\$i\" 'true'
377 check_sub_test_lib_test testlib-skip-tests-several <<-\\EOF
379 > ok 1 - passing test #1
380 > ok 2 # skip passing test #2 (TESTLIB_SKIP_TESTS)
381 > ok 3 - passing test #3
382 > ok 4 - passing test #4
383 > ok 5 # skip passing test #5 (TESTLIB_SKIP_TESTS)
384 > ok 6 - passing test #6
385 > # testlib passed all 6 test(s)
390 test_expect_success
'TESTLIB_SKIP_TESTS sh pattern' "
392 TESTLIB_SKIP_TESTS='testlib.[2-5]' && export TESTLIB_SKIP_TESTS &&
393 run_sub_test_lib_test testlib-skip-tests-sh-pattern \
394 'TESTLIB_SKIP_TESTS sh pattern' <<-\\EOF &&
398 test_expect_success \"passing test #\$i\" 'true'
402 check_sub_test_lib_test testlib-skip-tests-sh-pattern <<-\\EOF
404 > ok 1 - passing test #1
405 > ok 2 # skip passing test #2 (TESTLIB_SKIP_TESTS)
406 > ok 3 # skip passing test #3 (TESTLIB_SKIP_TESTS)
407 > ok 4 # skip passing test #4 (TESTLIB_SKIP_TESTS)
408 > ok 5 # skip passing test #5 (TESTLIB_SKIP_TESTS)
409 > ok 6 - passing test #6
410 > # testlib passed all 6 test(s)
415 test_expect_success
'--run basic' "
416 run_sub_test_lib_test run-basic \
417 '--run basic' --run='1 3 5' --no-quiet <<-\\EOF &&
421 test_expect_success \"passing test #\$i\" 'true'
425 check_sub_test_lib_test run-basic <<-\\EOF
427 > ok 1 - passing test #1
428 > ok 2 # skip passing test #2 (--run)
429 > ok 3 - passing test #3
430 > ok 4 # skip passing test #4 (--run)
431 > ok 5 - passing test #5
432 > ok 6 # skip passing test #6 (--run)
433 > # run passed all 6 test(s)
437 test_expect_success
'--run with a range' "
438 run_sub_test_lib_test run-range \
439 '--run with a range' --run='1-3' --no-quiet <<-\\EOF &&
443 test_expect_success \"passing test #\$i\" 'true'
447 check_sub_test_lib_test run-range <<-\\EOF
449 > ok 1 - passing test #1
450 > ok 2 - passing test #2
451 > ok 3 - passing test #3
452 > ok 4 # skip passing test #4 (--run)
453 > ok 5 # skip passing test #5 (--run)
454 > ok 6 # skip passing test #6 (--run)
455 > # run passed all 6 test(s)
459 test_expect_success
'--run with two ranges' "
460 run_sub_test_lib_test run-two-ranges \
461 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
465 test_expect_success \"passing test #\$i\" 'true'
469 check_sub_test_lib_test run-two-ranges <<-\\EOF
470 > ok 1 - passing test #1
471 > ok 2 - passing test #2
472 > ok 5 - passing test #5
473 > ok 6 - passing test #6
474 > # run passed all 6 test(s)
479 test_expect_success
'--run with a left open range' "
480 run_sub_test_lib_test run-left-open-range \
481 '--run with a left open range' --run='-3' --no-quiet <<-\\EOF &&
485 test_expect_success \"passing test #\$i\" 'true'
489 check_sub_test_lib_test run-left-open-range <<-\\EOF
491 > ok 1 - passing test #1
492 > ok 2 - passing test #2
493 > ok 3 - passing test #3
494 > ok 4 # skip passing test #4 (--run)
495 > ok 5 # skip passing test #5 (--run)
496 > ok 6 # skip passing test #6 (--run)
497 > # run passed all 6 test(s)
501 test_expect_success
'--run with a right open range' "
502 run_sub_test_lib_test run-right-open-range \
503 '--run with a right open range' --run='4-' --no-quiet <<-\\EOF &&
507 test_expect_success \"passing test #\$i\" 'true'
511 check_sub_test_lib_test run-right-open-range <<-\\EOF
513 > ok 1 # skip passing test #1 (--run)
514 > ok 2 # skip passing test #2 (--run)
515 > ok 3 # skip passing test #3 (--run)
516 > ok 4 - passing test #4
517 > ok 5 - passing test #5
518 > ok 6 - passing test #6
519 > # run passed all 6 test(s)
523 test_expect_success
'--run with basic negation' "
524 run_sub_test_lib_test run-basic-neg \
525 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
529 test_expect_success \"passing test #\$i\" 'true'
533 check_sub_test_lib_test run-basic-neg <<-\\EOF
534 > ok 1 - passing test #1
535 > ok 2 - passing test #2
536 > ok 4 - passing test #4
537 > ok 5 - passing test #5
538 > ok 6 - passing test #6
539 > # run passed all 6 test(s)
544 test_expect_success
'--run with two negations' "
545 run_sub_test_lib_test run-two-neg \
546 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
550 test_expect_success \"passing test #\$i\" 'true'
554 check_sub_test_lib_test run-two-neg <<-\\EOF
555 > ok 1 - passing test #1
556 > ok 2 - passing test #2
557 > ok 4 - passing test #4
558 > ok 5 - passing test #5
559 > # run passed all 6 test(s)
564 test_expect_success
'--run a range and negation' "
565 run_sub_test_lib_test run-range-and-neg \
566 '--run a range and negation' --run='"'-4 !2'"' --no-quiet <<-\\EOF &&
570 test_expect_success \"passing test #\$i\" 'true'
574 check_sub_test_lib_test run-range-and-neg <<-\\EOF
576 > ok 1 - passing test #1
577 > ok 2 # skip passing test #2 (--run)
578 > ok 3 - passing test #3
579 > ok 4 - passing test #4
580 > ok 5 # skip passing test #5 (--run)
581 > ok 6 # skip passing test #6 (--run)
582 > # run passed all 6 test(s)
586 test_expect_success
'--run range negation' "
587 run_sub_test_lib_test run-range-neg \
588 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
592 test_expect_success \"passing test #\$i\" 'true'
596 check_sub_test_lib_test run-range-neg <<-\\EOF
597 > ok 4 - passing test #4
598 > ok 5 - passing test #5
599 > ok 6 - passing test #6
600 > # run passed all 6 test(s)
605 test_expect_success
'--run include, exclude and include' "
606 run_sub_test_lib_test run-inc-neg-inc \
607 '--run include, exclude and include' \
608 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
612 test_expect_success \"passing test #\$i\" 'true'
616 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
617 > ok 2 - passing test #2
618 > ok 4 - passing test #4
619 > ok 5 - passing test #5
620 > # run passed all 6 test(s)
625 test_expect_success
'--run include, exclude and include, comma separated' "
626 run_sub_test_lib_test run-inc-neg-inc-comma \
627 '--run include, exclude and include, comma separated' \
628 --run=1-5,\!1-3,2 --no-quiet <<-\\EOF &&
632 test_expect_success \"passing test #\$i\" 'true'
636 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
638 > ok 1 # skip passing test #1 (--run)
639 > ok 2 - passing test #2
640 > ok 3 # skip passing test #3 (--run)
641 > ok 4 - passing test #4
642 > ok 5 - passing test #5
643 > ok 6 # skip passing test #6 (--run)
644 > # run passed all 6 test(s)
648 test_expect_success
'--run exclude and include' "
649 run_sub_test_lib_test run-neg-inc \
650 '--run exclude and include' \
651 --run='"'!3- 5'"' <<-\\EOF &&
655 test_expect_success \"passing test #\$i\" 'true'
659 check_sub_test_lib_test run-neg-inc <<-\\EOF
660 > ok 1 - passing test #1
661 > ok 2 - passing test #2
662 > ok 5 - passing test #5
663 > # run passed all 6 test(s)
668 test_expect_success
'--run empty selectors' "
669 run_sub_test_lib_test run-empty-sel \
670 '--run empty selectors' \
671 --run='1,,3,,,5' --no-quiet <<-\\EOF &&
675 test_expect_success \"passing test #\$i\" 'true'
679 check_sub_test_lib_test run-empty-sel <<-\\EOF
681 > ok 1 - passing test #1
682 > ok 2 # skip passing test #2 (--run)
683 > ok 3 - passing test #3
684 > ok 4 # skip passing test #4 (--run)
685 > ok 5 - passing test #5
686 > ok 6 # skip passing test #6 (--run)
687 > # run passed all 6 test(s)
691 test_expect_success
'--run invalid range start' "
692 run_sub_test_lib_test_err run-inv-range-start \
693 '--run invalid range start' \
694 --run='a-5' <<-\\EOF &&
695 test_expect_success \"passing test #1\" 'true'
698 check_sub_test_lib_test_err run-inv-range-start \
699 <<-\\EOF_OUT 3<<-\\EOF_ERR
700 > FATAL: Unexpected exit with code 1
702 > error: --run: invalid non-numeric in range start: 'a-5'
706 test_expect_success
'--run invalid range end' "
707 run_sub_test_lib_test_err run-inv-range-end \
708 '--run invalid range end' \
709 --run='1-z' <<-\\EOF &&
710 test_expect_success \"passing test #1\" 'true'
713 check_sub_test_lib_test_err run-inv-range-end \
714 <<-\\EOF_OUT 3<<-\\EOF_ERR
715 > FATAL: Unexpected exit with code 1
717 > error: --run: invalid non-numeric in range end: '1-z'
721 test_expect_success
'--run invalid selector' "
722 run_sub_test_lib_test_err run-inv-selector \
723 '--run invalid selector' \
724 --run='1?' <<-\\EOF &&
725 test_expect_success \"passing test #1\" 'true'
728 check_sub_test_lib_test_err run-inv-selector \
729 <<-\\EOF_OUT 3<<-\\EOF_ERR
730 > FATAL: Unexpected exit with code 1
732 > error: --run: invalid non-numeric in test selector: '1?'
737 test_set_prereq HAVEIT
739 echo "$haveit" >haveit
740 test_expect_success HAVEIT
'test runs if prerequisite is satisfied' '
741 test_have_prereq HAVEIT &&
743 echo "$haveit" >haveit
746 echo "$donthaveit" >donthaveit
747 test_expect_success DONTHAVEIT
'unmet prerequisite causes test to be skipped' '
749 echo "$donthaveit" >donthaveit
751 haveitf
="$(cat haveit)"
752 donthaveitf
="$(cat donthaveit)"
753 if test $haveit$donthaveit != noyes ||
test $haveitf$donthaveitf != yesyes
755 say
"bug in test framework: prerequisite tags do not work reliably"
759 # Stop with the fussing with files
760 TESTLIB_TEST_NO_SUBSHELL
=1
762 test_set_prereq HAVETHIS
764 test_expect_success HAVETHIS
,HAVEIT
'test runs if prerequisites are satisfied' '
765 test_have_prereq HAVEIT &&
766 test_have_prereq HAVETHIS &&
770 test_expect_success HAVEIT
,DONTHAVEIT
'unmet prerequisites causes test to be skipped' '
774 test_expect_success DONTHAVEIT
,HAVEIT
'unmet prerequisites causes test to be skipped' '
777 if test $haveit$donthaveit$donthaveiteither != yesyesyes
779 say
"bug in test framework: multiple prerequisite tags do not work reliably"
783 test_lazy_prereq LAZY_TRUE true
785 test_expect_success LAZY_TRUE
'test runs if lazy prereq is satisfied' '
789 test_expect_success
!LAZY_TRUE
'missing lazy prereqs skip tests' '
793 if test "$havetrue$donthavetrue" != yesyes
795 say
'bug in test framework: lazy prerequisites do not work'
799 test_lazy_prereq LAZY_FALSE false
801 test_expect_success
!LAZY_FALSE
'negative lazy prereqs checked' '
805 test_expect_success LAZY_FALSE
'missing negative lazy prereqs will skip' '
809 if test "$nothavefalse$havefalse" != yesyes
811 say
'bug in test framework: negative lazy prerequisites do not work'
815 # Mostly done with the no subshell tests
816 sane_unset TESTLIB_TEST_NO_SUBSHELL
819 test_expect_success
'tests clean up after themselves' '
820 test_when_finished clean=yes
823 if test $clean != yes
825 say
"bug in test framework: basic cleanup command does not work reliably"
829 test_expect_success
'tests clean up even on failures' "
830 test_must_fail run_sub_test_lib_test \
831 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
833 test_expect_success 'tests clean up even after a failure' '
834 touch clean-after-failure &&
835 test_when_finished rm clean-after-failure &&
838 test_expect_success 'failure to clean up causes the test to fail' '
839 test_when_finished eval \"(exit 2)\"
843 check_sub_test_lib_test failing-cleanup <<-\\EOF
845 > not ok 1 - tests clean up even after a failure
846 > # failed: failing-cleanup.sh
848 > # touch clean-after-failure &&
849 > # test_when_finished rm clean-after-failure &&
852 > not ok 2 - failure to clean up causes the test to fail
853 > # failed: failing-cleanup.sh
855 > # test_when_finished eval \"(exit 2)\"
857 > # failing failed 2 among 2 test(s)
861 ################################################################
862 # Basics of the basics
864 # updating a new file without --add should fail.
865 test_expect_success
'git update-index without --add should fail adding' '
866 test_must_fail git update-index should-be-empty
869 # and with --add it should succeed, even if it is empty (it used to fail).
870 test_expect_success
'git update-index with --add should succeed' '
871 git update-index --add should-be-empty
874 TESTLIB_TEST_NO_SUBSHELL
=1
875 test_expect_success
'writing tree out with git write-tree' '
876 tree=$(git write-tree)
878 sane_unset TESTLIB_TEST_NO_SUBSHELL
880 # we know the shape and contents of the tree and know the object ID for it.
881 test_expect_success
'validate object ID of a known tree' '
882 test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
886 test_expect_success
'git update-index without --remove should fail removing' '
887 rm -f should-be-empty full-of-directories &&
888 test_must_fail git update-index should-be-empty
891 test_expect_success
'git update-index with --remove should be able to remove' '
892 git update-index --remove should-be-empty
895 # Empty tree can be written with recent write-tree.
896 TESTLIB_TEST_NO_SUBSHELL
=1
897 test_tolerate_failure
'git write-tree should be able to write an empty tree' '
898 tree=$(git write-tree)
900 sane_unset TESTLIB_TEST_NO_SUBSHELL
904 test_result
='test_expect_success'
906 test_result
='test_tolerate_failure'
908 $test_result 'validate object ID of a known tree' '
909 test "$tree" = $EMPTY_TREE
912 # Various types of objects
914 test_expect_success
'adding various types of objects with git update-index --add' '
915 mkdir path2 path3 path3/subp3 &&
916 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
920 echo "hello $p" >$p || exit 1
921 test_ln_s_add "hello $p" ${p}sym || exit 1
924 find path* ! -type d -print | xargs git update-index --add
927 # Show them and see that matches what we expect.
928 test_expect_success
'showing stage with git ls-files --stage' '
929 git ls-files --stage >current
932 test_expect_success
'validate git ls-files output for a known tree' '
933 cat >expected <<-\EOF &&
934 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
935 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
936 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
937 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
938 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
939 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
940 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
941 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
943 test_cmp expected current
946 TESTLIB_TEST_NO_SUBSHELL
=1
947 test_expect_success
'writing tree out with git write-tree' '
948 tree=$(git write-tree)
950 sane_unset TESTLIB_TEST_NO_SUBSHELL
952 test_expect_success
'validate object ID for a known tree' '
953 test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
956 test_expect_success
'showing tree with git ls-tree' '
957 git ls-tree $tree >current
960 test_expect_success
'git ls-tree output for a known tree' '
961 cat >expected <<-\EOF &&
962 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
963 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
964 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
965 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
967 test_cmp expected current
970 # This changed in ls-tree pathspec change -- recursive does
971 # not show tree nodes anymore.
972 test_expect_success
'showing tree with git ls-tree -r' '
973 git ls-tree -r $tree >current
976 test_expect_success
'git ls-tree -r output for a known tree' '
977 cat >expected <<-\EOF &&
978 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
979 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
980 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
981 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
982 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
983 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
984 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
985 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
987 test_cmp expected current
990 # But with -r -t we can have both.
991 test_expect_success
'showing tree with git ls-tree -r -t' '
992 git ls-tree -r -t $tree >current
995 test_expect_success
'git ls-tree -r output for a known tree' '
996 cat >expected <<-\EOF &&
997 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
998 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
999 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
1000 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
1001 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
1002 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
1003 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
1004 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
1005 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
1006 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
1007 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
1009 test_cmp expected current
1012 TESTLIB_TEST_NO_SUBSHELL
=1
1013 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1014 ptree=$(git write-tree --prefix=path3)
1016 sane_unset TESTLIB_TEST_NO_SUBSHELL
1018 test_expect_success
'validate object ID for a known tree' '
1019 test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
1022 TESTLIB_TEST_NO_SUBSHELL
=1
1023 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1024 ptree=$(git write-tree --prefix=path3/subp3)
1026 sane_unset TESTLIB_TEST_NO_SUBSHELL
1028 test_expect_success
'validate object ID for a known tree' '
1029 test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
1032 test_expect_success
'put invalid objects into the index' '
1034 cat >badobjects <<-\EOF &&
1035 100644 blob 1000000000000000000000000000000000000000 dir/file1
1036 100644 blob 2000000000000000000000000000000000000000 dir/file2
1037 100644 blob 3000000000000000000000000000000000000000 dir/file3
1038 100644 blob 4000000000000000000000000000000000000000 dir/file4
1039 100644 blob 5000000000000000000000000000000000000000 dir/file5
1041 git update-index --index-info <badobjects
1044 test_expect_success
'writing this tree without --missing-ok' '
1045 test_must_fail git write-tree
1048 test_expect_success
'writing this tree with --missing-ok' '
1049 git write-tree --missing-ok
1053 ################################################################
1054 test_expect_success
'git read-tree followed by write-tree should be idempotent' '
1056 git read-tree $tree &&
1057 test -f .git/index &&
1058 newtree=$(git write-tree) &&
1059 test "$newtree" = "$tree"
1062 test_expect_success
'validate git diff-files output for a know cache/work tree state' '
1063 cat >expected <<\EOF &&
1064 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
1065 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
1066 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
1067 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
1068 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
1069 :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
1070 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
1071 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
1073 git diff-files >current &&
1074 test_cmp current expected
1077 test_expect_success
'git update-index --refresh should succeed' '
1078 git update-index --refresh
1081 test_expect_success
'no diff after checkout and git update-index --refresh' '
1082 git diff-files >current &&
1083 cmp -s current /dev/null
1086 ################################################################
1087 P
=087704a96baf1c2d1c869a8b084481e121c88b5b
1089 TESTLIB_TEST_NO_SUBSHELL
=1
1090 test_expect_success
'git commit-tree records the correct tree in a commit' '
1091 commit0=$(echo NO | git commit-tree $P) &&
1092 tree=$(git show --pretty=raw $commit0 |
1093 sed -n -e "s/^tree //p" -e "/^author /q") &&
1094 test "z$tree" = "z$P"
1096 sane_unset TESTLIB_TEST_NO_SUBSHELL
1098 test_expect_success
'git commit-tree records the correct parent in a commit' '
1099 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1100 parent=$(git show --pretty=raw $commit1 |
1101 sed -n -e "s/^parent //p" -e "/^author /q") &&
1102 test "z$commit0" = "z$parent"
1105 test_expect_success
'git commit-tree omits duplicated parent in a commit' '
1106 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1107 parent=$(git show --pretty=raw $commit2 |
1108 sed -n -e "s/^parent //p" -e "/^author /q" |
1110 test "z$commit0" = "z$parent" &&
1111 numparent=$(git show --pretty=raw $commit2 |
1112 sed -n -e "s/^parent //p" -e "/^author /q" |
1117 test_expect_success
'update-index D/F conflict' '
1121 git update-index --add --replace path2 path0/file2 &&
1122 numpath0=$(git ls-files path0 | wc -l) &&
1126 test_expect_success
'very long name in the index handled sanely' '
1129 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1130 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1131 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1135 git update-index --add path4 &&
1137 git ls-files -s path4 |
1141 ) | git update-index --index-info &&
1142 len=$(git ls-files "a*" | wc -c) &&