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.
23 ################################################################
24 # git init has been done in an empty repository.
25 # make sure it is empty.
27 test_expect_success
'.git/objects should be empty after git init in an empty repo' '
28 find .git/objects -type f -print >should-be-empty &&
29 test_line_count = 0 should-be-empty
32 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
33 # 3 is counting "objects" itself
34 test_expect_success
'.git/objects should have 3 subdirectories' '
35 find .git/objects -type d -print >full-of-directories &&
36 test_line_count = 3 full-of-directories
39 ################################################################
41 test_expect_success
'success is reported like this' '
45 _run_sub_test_lib_test_common
() {
46 neg
="$1" name
="$2" descr
="$3" # stdin is the body of the test code
50 # Pretend we're not running under a test harness, whether we
51 # are or not. The test-lib output depends on the setting of
52 # this variable, so we need a stable setting under which to run
54 sane_unset HARNESS_ACTIVE
&&
56 cat >"$name.sh" <<-EOF &&
59 test_description='$descr (run in sub test-lib)
61 This is run in a sub test-lib so that we do not get incorrect
65 # Point to the t/test-lib.sh, which isn't in ../ as usual
66 . "\$TEST_DIRECTORY"/test-lib.sh
69 chmod +x
"$name.sh" &&
70 export TEST_DIRECTORY
&&
71 TEST_OUTPUT_DIRECTORY
=$
(pwd) &&
72 export TEST_OUTPUT_DIRECTORY
&&
75 .
/"$name.sh" "$@" >out
2>err
77 ! .
/"$name.sh" "$@" >out
2>err
82 run_sub_test_lib_test
() {
83 _run_sub_test_lib_test_common
'' "$@"
86 run_sub_test_lib_test_err
() {
87 _run_sub_test_lib_test_common
'!' "$@"
90 check_sub_test_lib_test
() {
91 name
="$1" # stdin is the expected output from the test
95 sed -e 's/^> //' -e 's/Z$//' >expect
&&
100 check_sub_test_lib_test_err
() {
101 name
="$1" # stdin is the expected output output from the test
102 # expected error output is in descriptior 3
105 sed -e 's/^> //' -e 's/Z$//' >expect.out
&&
106 test_cmp expect.out out
&&
107 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err
&&
108 test_cmp expect.err err
112 test_expect_success
'pretend we have a fully passing test suite' "
113 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
116 test_expect_success \"passing test #\$i\" 'true'
120 check_sub_test_lib_test full-pass <<-\\EOF
121 > ok 1 - passing test #1
122 > ok 2 - passing test #2
123 > ok 3 - passing test #3
124 > # passed all 3 test(s)
129 test_expect_success
'pretend we have a partially passing test suite' "
130 test_must_fail run_sub_test_lib_test \
131 partial-pass '2/3 tests passing' <<-\\EOF &&
132 test_expect_success 'passing test #1' 'true'
133 test_expect_success 'failing test #2' 'false'
134 test_expect_success 'passing test #3' 'true'
137 check_sub_test_lib_test partial-pass <<-\\EOF
138 > ok 1 - passing test #1
139 > not ok 2 - failing test #2
141 > ok 3 - passing test #3
142 > # failed 1 among 3 test(s)
147 test_expect_success
'pretend we have a known breakage' "
148 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
149 test_expect_success 'passing test' 'true'
150 test_expect_failure 'pretend we have a known breakage' 'false'
153 check_sub_test_lib_test failing-todo <<-\\EOF
154 > ok 1 - passing test
155 > not ok 2 - pretend we have a known breakage # TODO known breakage
156 > # still have 1 known breakage(s)
157 > # passed all remaining 1 test(s)
162 test_expect_success
'pretend we have fixed a known breakage' "
163 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
164 test_expect_failure 'pretend we have fixed a known breakage' 'true'
167 check_sub_test_lib_test passing-todo <<-\\EOF
168 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
169 > # 1 known breakage(s) vanished; please update test(s)
174 test_expect_success
'pretend we have fixed one of two known breakages (run in sub test-lib)' "
175 run_sub_test_lib_test partially-passing-todos \
176 '2 TODO tests, one passing' <<-\\EOF &&
177 test_expect_failure 'pretend we have a known breakage' 'false'
178 test_expect_success 'pretend we have a passing test' 'true'
179 test_expect_failure 'pretend we have fixed another known breakage' 'true'
182 check_sub_test_lib_test partially-passing-todos <<-\\EOF
183 > not ok 1 - pretend we have a known breakage # TODO known breakage
184 > ok 2 - pretend we have a passing test
185 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
186 > # 1 known breakage(s) vanished; please update test(s)
187 > # still have 1 known breakage(s)
188 > # passed all remaining 1 test(s)
193 test_expect_success
'pretend we have a pass, fail, and known breakage' "
194 test_must_fail run_sub_test_lib_test \
195 mixed-results1 'mixed results #1' <<-\\EOF &&
196 test_expect_success 'passing test' 'true'
197 test_expect_success 'failing test' 'false'
198 test_expect_failure 'pretend we have a known breakage' 'false'
201 check_sub_test_lib_test mixed-results1 <<-\\EOF
202 > ok 1 - passing test
203 > not ok 2 - failing test
205 > not ok 3 - pretend we have a known breakage # TODO known breakage
206 > # still have 1 known breakage(s)
207 > # failed 1 among remaining 2 test(s)
212 test_expect_success
'pretend we have a mix of all possible results' "
213 test_must_fail run_sub_test_lib_test \
214 mixed-results2 'mixed results #2' <<-\\EOF &&
215 test_expect_success 'passing test' 'true'
216 test_expect_success 'passing test' 'true'
217 test_expect_success 'passing test' 'true'
218 test_expect_success 'passing test' 'true'
219 test_expect_success 'failing test' 'false'
220 test_expect_success 'failing test' 'false'
221 test_expect_success 'failing test' 'false'
222 test_expect_failure 'pretend we have a known breakage' 'false'
223 test_expect_failure 'pretend we have a known breakage' 'false'
224 test_expect_failure 'pretend we have fixed a known breakage' 'true'
227 check_sub_test_lib_test mixed-results2 <<-\\EOF
228 > ok 1 - passing test
229 > ok 2 - passing test
230 > ok 3 - passing test
231 > ok 4 - passing test
232 > not ok 5 - failing test
234 > not ok 6 - failing test
236 > not ok 7 - failing test
238 > not ok 8 - pretend we have a known breakage # TODO known breakage
239 > not ok 9 - pretend we have a known breakage # TODO known breakage
240 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
241 > # 1 known breakage(s) vanished; please update test(s)
242 > # still have 2 known breakage(s)
243 > # failed 3 among remaining 7 test(s)
248 test_expect_success
'test --verbose' '
249 test_must_fail run_sub_test_lib_test \
250 test-verbose "test verbose" --verbose <<-\EOF &&
251 test_expect_success "passing test" true
252 test_expect_success "test with output" "echo foo"
253 test_expect_success "failing test" false
256 mv test-verbose/out test-verbose/out+
257 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
258 check_sub_test_lib_test test-verbose <<-\EOF
259 > expecting success: true
260 > ok 1 - passing test
262 > expecting success: echo foo
264 > ok 2 - test with output
266 > expecting success: false
267 > not ok 3 - failing test
270 > # failed 1 among 3 test(s)
275 test_expect_success
'test --verbose-only' '
276 test_must_fail run_sub_test_lib_test \
277 test-verbose-only-2 "test verbose-only=2" \
278 --verbose-only=2 <<-\EOF &&
279 test_expect_success "passing test" true
280 test_expect_success "test with output" "echo foo"
281 test_expect_success "failing test" false
284 check_sub_test_lib_test test-verbose-only-2 <<-\EOF
285 > ok 1 - passing test
287 > expecting success: echo foo
289 > ok 2 - test with output
291 > not ok 3 - failing test
293 > # failed 1 among 3 test(s)
298 test_expect_success
'GIT_SKIP_TESTS' "
299 GIT_SKIP_TESTS='git.2' \
300 run_sub_test_lib_test git-skip-tests-basic \
301 'GIT_SKIP_TESTS' <<-\\EOF &&
304 test_expect_success \"passing test #\$i\" 'true'
308 check_sub_test_lib_test git-skip-tests-basic <<-\\EOF
309 > ok 1 - passing test #1
310 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
311 > ok 3 - passing test #3
312 > # passed all 3 test(s)
317 test_expect_success
'GIT_SKIP_TESTS several tests' "
318 GIT_SKIP_TESTS='git.2 git.5' \
319 run_sub_test_lib_test git-skip-tests-several \
320 'GIT_SKIP_TESTS several tests' <<-\\EOF &&
323 test_expect_success \"passing test #\$i\" 'true'
327 check_sub_test_lib_test git-skip-tests-several <<-\\EOF
328 > ok 1 - passing test #1
329 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
330 > ok 3 - passing test #3
331 > ok 4 - passing test #4
332 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
333 > ok 6 - passing test #6
334 > # passed all 6 test(s)
339 test_expect_success
'GIT_SKIP_TESTS sh pattern' "
340 GIT_SKIP_TESTS='git.[2-5]' \
341 run_sub_test_lib_test git-skip-tests-sh-pattern \
342 'GIT_SKIP_TESTS sh pattern' <<-\\EOF &&
345 test_expect_success \"passing test #\$i\" 'true'
349 check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF
350 > ok 1 - passing test #1
351 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
352 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
353 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
354 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
355 > ok 6 - passing test #6
356 > # passed all 6 test(s)
361 test_expect_success
'--run basic' "
362 run_sub_test_lib_test run-basic \
363 '--run basic' --run='1 3 5' <<-\\EOF &&
366 test_expect_success \"passing test #\$i\" 'true'
370 check_sub_test_lib_test run-basic <<-\\EOF
371 > ok 1 - passing test #1
372 > ok 2 # skip passing test #2 (--run)
373 > ok 3 - passing test #3
374 > ok 4 # skip passing test #4 (--run)
375 > ok 5 - passing test #5
376 > ok 6 # skip passing test #6 (--run)
377 > # passed all 6 test(s)
382 test_expect_success
'--run with a range' "
383 run_sub_test_lib_test run-range \
384 '--run with a range' --run='1-3' <<-\\EOF &&
387 test_expect_success \"passing test #\$i\" 'true'
391 check_sub_test_lib_test run-range <<-\\EOF
392 > ok 1 - passing test #1
393 > ok 2 - passing test #2
394 > ok 3 - passing test #3
395 > ok 4 # skip passing test #4 (--run)
396 > ok 5 # skip passing test #5 (--run)
397 > ok 6 # skip passing test #6 (--run)
398 > # passed all 6 test(s)
403 test_expect_success
'--run with two ranges' "
404 run_sub_test_lib_test run-two-ranges \
405 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
408 test_expect_success \"passing test #\$i\" 'true'
412 check_sub_test_lib_test run-two-ranges <<-\\EOF
413 > ok 1 - passing test #1
414 > ok 2 - passing test #2
415 > ok 3 # skip passing test #3 (--run)
416 > ok 4 # skip passing test #4 (--run)
417 > ok 5 - passing test #5
418 > ok 6 - passing test #6
419 > # passed all 6 test(s)
424 test_expect_success
'--run with a left open range' "
425 run_sub_test_lib_test run-left-open-range \
426 '--run with a left open range' --run='-3' <<-\\EOF &&
429 test_expect_success \"passing test #\$i\" 'true'
433 check_sub_test_lib_test run-left-open-range <<-\\EOF
434 > ok 1 - passing test #1
435 > ok 2 - passing test #2
436 > ok 3 - passing test #3
437 > ok 4 # skip passing test #4 (--run)
438 > ok 5 # skip passing test #5 (--run)
439 > ok 6 # skip passing test #6 (--run)
440 > # passed all 6 test(s)
445 test_expect_success
'--run with a right open range' "
446 run_sub_test_lib_test run-right-open-range \
447 '--run with a right open range' --run='4-' <<-\\EOF &&
450 test_expect_success \"passing test #\$i\" 'true'
454 check_sub_test_lib_test run-right-open-range <<-\\EOF
455 > ok 1 # skip passing test #1 (--run)
456 > ok 2 # skip passing test #2 (--run)
457 > ok 3 # skip passing test #3 (--run)
458 > ok 4 - passing test #4
459 > ok 5 - passing test #5
460 > ok 6 - passing test #6
461 > # passed all 6 test(s)
466 test_expect_success
'--run with basic negation' "
467 run_sub_test_lib_test run-basic-neg \
468 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
471 test_expect_success \"passing test #\$i\" 'true'
475 check_sub_test_lib_test run-basic-neg <<-\\EOF
476 > ok 1 - passing test #1
477 > ok 2 - passing test #2
478 > ok 3 # skip passing test #3 (--run)
479 > ok 4 - passing test #4
480 > ok 5 - passing test #5
481 > ok 6 - passing test #6
482 > # passed all 6 test(s)
487 test_expect_success
'--run with two negations' "
488 run_sub_test_lib_test run-two-neg \
489 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
492 test_expect_success \"passing test #\$i\" 'true'
496 check_sub_test_lib_test run-two-neg <<-\\EOF
497 > ok 1 - passing test #1
498 > ok 2 - passing test #2
499 > ok 3 # skip passing test #3 (--run)
500 > ok 4 - passing test #4
501 > ok 5 - passing test #5
502 > ok 6 # skip passing test #6 (--run)
503 > # passed all 6 test(s)
508 test_expect_success
'--run a range and negation' "
509 run_sub_test_lib_test run-range-and-neg \
510 '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
513 test_expect_success \"passing test #\$i\" 'true'
517 check_sub_test_lib_test run-range-and-neg <<-\\EOF
518 > ok 1 - passing test #1
519 > ok 2 # skip passing test #2 (--run)
520 > ok 3 - passing test #3
521 > ok 4 - passing test #4
522 > ok 5 # skip passing test #5 (--run)
523 > ok 6 # skip passing test #6 (--run)
524 > # passed all 6 test(s)
529 test_expect_success
'--run range negation' "
530 run_sub_test_lib_test run-range-neg \
531 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
534 test_expect_success \"passing test #\$i\" 'true'
538 check_sub_test_lib_test run-range-neg <<-\\EOF
539 > ok 1 # skip passing test #1 (--run)
540 > ok 2 # skip passing test #2 (--run)
541 > ok 3 # skip passing test #3 (--run)
542 > ok 4 - passing test #4
543 > ok 5 - passing test #5
544 > ok 6 - passing test #6
545 > # passed all 6 test(s)
550 test_expect_success
'--run include, exclude and include' "
551 run_sub_test_lib_test run-inc-neg-inc \
552 '--run include, exclude and include' \
553 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
556 test_expect_success \"passing test #\$i\" 'true'
560 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
561 > ok 1 # skip passing test #1 (--run)
562 > ok 2 - passing test #2
563 > ok 3 # skip passing test #3 (--run)
564 > ok 4 - passing test #4
565 > ok 5 - passing test #5
566 > ok 6 # skip passing test #6 (--run)
567 > # passed all 6 test(s)
572 test_expect_success
'--run include, exclude and include, comma separated' "
573 run_sub_test_lib_test run-inc-neg-inc-comma \
574 '--run include, exclude and include, comma separated' \
575 --run=1-5,\!1-3,2 <<-\\EOF &&
578 test_expect_success \"passing test #\$i\" 'true'
582 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
583 > ok 1 # skip passing test #1 (--run)
584 > ok 2 - passing test #2
585 > ok 3 # skip passing test #3 (--run)
586 > ok 4 - passing test #4
587 > ok 5 - passing test #5
588 > ok 6 # skip passing test #6 (--run)
589 > # passed all 6 test(s)
594 test_expect_success
'--run exclude and include' "
595 run_sub_test_lib_test run-neg-inc \
596 '--run exclude and include' \
597 --run='"'!3- 5'"' <<-\\EOF &&
600 test_expect_success \"passing test #\$i\" 'true'
604 check_sub_test_lib_test run-neg-inc <<-\\EOF
605 > ok 1 - passing test #1
606 > ok 2 - passing test #2
607 > ok 3 # skip passing test #3 (--run)
608 > ok 4 # skip passing test #4 (--run)
609 > ok 5 - passing test #5
610 > ok 6 # skip passing test #6 (--run)
611 > # passed all 6 test(s)
616 test_expect_success
'--run empty selectors' "
617 run_sub_test_lib_test run-empty-sel \
618 '--run empty selectors' \
619 --run='1,,3,,,5' <<-\\EOF &&
622 test_expect_success \"passing test #\$i\" 'true'
626 check_sub_test_lib_test run-empty-sel <<-\\EOF
627 > ok 1 - passing test #1
628 > ok 2 # skip passing test #2 (--run)
629 > ok 3 - passing test #3
630 > ok 4 # skip passing test #4 (--run)
631 > ok 5 - passing test #5
632 > ok 6 # skip passing test #6 (--run)
633 > # passed all 6 test(s)
638 test_expect_success
'--run invalid range start' "
639 run_sub_test_lib_test_err run-inv-range-start \
640 '--run invalid range start' \
641 --run='a-5' <<-\\EOF &&
642 test_expect_success \"passing test #1\" 'true'
645 check_sub_test_lib_test_err run-inv-range-start \
646 <<-\\EOF_OUT 3<<-\\EOF_ERR
647 > FATAL: Unexpected exit with code 1
649 > error: --run: invalid non-numeric in range start: 'a-5'
653 test_expect_success
'--run invalid range end' "
654 run_sub_test_lib_test_err run-inv-range-end \
655 '--run invalid range end' \
656 --run='1-z' <<-\\EOF &&
657 test_expect_success \"passing test #1\" 'true'
660 check_sub_test_lib_test_err run-inv-range-end \
661 <<-\\EOF_OUT 3<<-\\EOF_ERR
662 > FATAL: Unexpected exit with code 1
664 > error: --run: invalid non-numeric in range end: '1-z'
668 test_expect_success
'--run invalid selector' "
669 run_sub_test_lib_test_err run-inv-selector \
670 '--run invalid selector' \
671 --run='1?' <<-\\EOF &&
672 test_expect_success \"passing test #1\" 'true'
675 check_sub_test_lib_test_err run-inv-selector \
676 <<-\\EOF_OUT 3<<-\\EOF_ERR
677 > FATAL: Unexpected exit with code 1
679 > error: --run: invalid non-numeric in test selector: '1?'
684 test_set_prereq HAVEIT
686 test_expect_success HAVEIT
'test runs if prerequisite is satisfied' '
687 test_have_prereq HAVEIT &&
691 test_expect_success DONTHAVEIT
'unmet prerequisite causes test to be skipped' '
694 if test $haveit$donthaveit != yesyes
696 say
"bug in test framework: prerequisite tags do not work reliably"
700 test_set_prereq HAVETHIS
702 test_expect_success HAVETHIS
,HAVEIT
'test runs if prerequisites are satisfied' '
703 test_have_prereq HAVEIT &&
704 test_have_prereq HAVETHIS &&
708 test_expect_success HAVEIT
,DONTHAVEIT
'unmet prerequisites causes test to be skipped' '
712 test_expect_success DONTHAVEIT
,HAVEIT
'unmet prerequisites causes test to be skipped' '
715 if test $haveit$donthaveit$donthaveiteither != yesyesyes
717 say
"bug in test framework: multiple prerequisite tags do not work reliably"
721 test_lazy_prereq LAZY_TRUE true
723 test_expect_success LAZY_TRUE
'test runs if lazy prereq is satisfied' '
727 test_expect_success
!LAZY_TRUE
'missing lazy prereqs skip tests' '
731 if test "$havetrue$donthavetrue" != yesyes
733 say
'bug in test framework: lazy prerequisites do not work'
737 test_lazy_prereq LAZY_FALSE false
739 test_expect_success
!LAZY_FALSE
'negative lazy prereqs checked' '
743 test_expect_success LAZY_FALSE
'missing negative lazy prereqs will skip' '
747 if test "$nothavefalse$havefalse" != yesyes
749 say
'bug in test framework: negative lazy prerequisites do not work'
754 test_expect_success
'tests clean up after themselves' '
755 test_when_finished clean=yes
758 if test $clean != yes
760 say
"bug in test framework: basic cleanup command does not work reliably"
764 test_expect_success
'tests clean up even on failures' "
765 test_must_fail run_sub_test_lib_test \
766 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
767 test_expect_success 'tests clean up even after a failure' '
768 touch clean-after-failure &&
769 test_when_finished rm clean-after-failure &&
772 test_expect_success 'failure to clean up causes the test to fail' '
773 test_when_finished \"(exit 2)\"
777 check_sub_test_lib_test failing-cleanup <<-\\EOF
778 > not ok 1 - tests clean up even after a failure
780 > # touch clean-after-failure &&
781 > # test_when_finished rm clean-after-failure &&
784 > not ok 2 - failure to clean up causes the test to fail
786 > # test_when_finished \"(exit 2)\"
788 > # failed 2 among 2 test(s)
793 ################################################################
794 # Basics of the basics
796 # updating a new file without --add should fail.
797 test_expect_success
'git update-index without --add should fail adding' '
798 test_must_fail git update-index should-be-empty
801 # and with --add it should succeed, even if it is empty (it used to fail).
802 test_expect_success
'git update-index with --add should succeed' '
803 git update-index --add should-be-empty
806 test_expect_success
'writing tree out with git write-tree' '
807 tree=$(git write-tree)
810 # we know the shape and contents of the tree and know the object ID for it.
811 test_expect_success
'validate object ID of a known tree' '
812 test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
816 test_expect_success
'git update-index without --remove should fail removing' '
817 rm -f should-be-empty full-of-directories &&
818 test_must_fail git update-index should-be-empty
821 test_expect_success
'git update-index with --remove should be able to remove' '
822 git update-index --remove should-be-empty
825 # Empty tree can be written with recent write-tree.
826 test_expect_success
'git write-tree should be able to write an empty tree' '
827 tree=$(git write-tree)
830 test_expect_success
'validate object ID of a known tree' '
831 test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904
834 # Various types of objects
836 test_expect_success
'adding various types of objects with git update-index --add' '
837 mkdir path2 path3 path3/subp3 &&
838 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
842 echo "hello $p" >$p || exit 1
843 test_ln_s_add "hello $p" ${p}sym || exit 1
846 find path* ! -type d -print | xargs git update-index --add
849 # Show them and see that matches what we expect.
850 test_expect_success
'showing stage with git ls-files --stage' '
851 git ls-files --stage >current
854 test_expect_success
'validate git ls-files output for a known tree' '
855 cat >expected <<-\EOF &&
856 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
857 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
858 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
859 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
860 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
861 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
862 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
863 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
865 test_cmp expected current
868 test_expect_success
'writing tree out with git write-tree' '
869 tree=$(git write-tree)
872 test_expect_success
'validate object ID for a known tree' '
873 test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
876 test_expect_success
'showing tree with git ls-tree' '
877 git ls-tree $tree >current
880 test_expect_success
'git ls-tree output for a known tree' '
881 cat >expected <<-\EOF &&
882 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
883 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
884 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
885 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
887 test_cmp expected current
890 # This changed in ls-tree pathspec change -- recursive does
891 # not show tree nodes anymore.
892 test_expect_success
'showing tree with git ls-tree -r' '
893 git ls-tree -r $tree >current
896 test_expect_success
'git ls-tree -r output for a known tree' '
897 cat >expected <<-\EOF &&
898 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
899 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
900 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
901 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
902 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
903 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
904 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
905 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
907 test_cmp expected current
910 # But with -r -t we can have both.
911 test_expect_success
'showing tree with git ls-tree -r -t' '
912 git ls-tree -r -t $tree >current
915 test_expect_success
'git ls-tree -r output for a known tree' '
916 cat >expected <<-\EOF &&
917 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
918 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
919 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
920 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
921 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
922 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
923 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
924 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
925 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
926 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
927 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
929 test_cmp expected current
932 test_expect_success
'writing partial tree out with git write-tree --prefix' '
933 ptree=$(git write-tree --prefix=path3)
936 test_expect_success
'validate object ID for a known tree' '
937 test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
940 test_expect_success
'writing partial tree out with git write-tree --prefix' '
941 ptree=$(git write-tree --prefix=path3/subp3)
944 test_expect_success
'validate object ID for a known tree' '
945 test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
948 test_expect_success
'put invalid objects into the index' '
950 cat >badobjects <<-\EOF &&
951 100644 blob 1000000000000000000000000000000000000000 dir/file1
952 100644 blob 2000000000000000000000000000000000000000 dir/file2
953 100644 blob 3000000000000000000000000000000000000000 dir/file3
954 100644 blob 4000000000000000000000000000000000000000 dir/file4
955 100644 blob 5000000000000000000000000000000000000000 dir/file5
957 git update-index --index-info <badobjects
960 test_expect_success
'writing this tree without --missing-ok' '
961 test_must_fail git write-tree
964 test_expect_success
'writing this tree with --missing-ok' '
965 git write-tree --missing-ok
969 ################################################################
970 test_expect_success
'git read-tree followed by write-tree should be idempotent' '
972 git read-tree $tree &&
973 test -f .git/index &&
974 newtree=$(git write-tree) &&
975 test "$newtree" = "$tree"
978 test_expect_success
'validate git diff-files output for a know cache/work tree state' '
979 cat >expected <<\EOF &&
980 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
981 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
982 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
983 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
984 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
985 :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
986 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
987 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
989 git diff-files >current &&
990 test_cmp current expected
993 test_expect_success
'git update-index --refresh should succeed' '
994 git update-index --refresh
997 test_expect_success
'no diff after checkout and git update-index --refresh' '
998 git diff-files >current &&
999 cmp -s current /dev/null
1002 ################################################################
1003 P
=087704a96baf1c2d1c869a8b084481e121c88b5b
1005 test_expect_success
'git commit-tree records the correct tree in a commit' '
1006 commit0=$(echo NO | git commit-tree $P) &&
1007 tree=$(git show --pretty=raw $commit0 |
1008 sed -n -e "s/^tree //p" -e "/^author /q") &&
1009 test "z$tree" = "z$P"
1012 test_expect_success
'git commit-tree records the correct parent in a commit' '
1013 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1014 parent=$(git show --pretty=raw $commit1 |
1015 sed -n -e "s/^parent //p" -e "/^author /q") &&
1016 test "z$commit0" = "z$parent"
1019 test_expect_success
'git commit-tree omits duplicated parent in a commit' '
1020 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1021 parent=$(git show --pretty=raw $commit2 |
1022 sed -n -e "s/^parent //p" -e "/^author /q" |
1024 test "z$commit0" = "z$parent" &&
1025 numparent=$(git show --pretty=raw $commit2 |
1026 sed -n -e "s/^parent //p" -e "/^author /q" |
1031 test_expect_success
'update-index D/F conflict' '
1035 git update-index --add --replace path2 path0/file2 &&
1036 numpath0=$(git ls-files path0 | wc -l) &&
1040 test_expect_success
'very long name in the index handled sanely' '
1043 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1044 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1045 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1049 git update-index --add path4 &&
1051 git ls-files -s path4 |
1055 ) | git update-index --index-info &&
1056 len=$(git ls-files "a*" | wc -c) &&