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