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