t / t5318-commit-graph.shon commit Merge branch 'nd/switch-and-restore' (3ff6af7)
   1#!/bin/sh
   2
   3test_description='commit graph'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup full repo' '
   7        mkdir full &&
   8        cd "$TRASH_DIRECTORY/full" &&
   9        git init &&
  10        git config core.commitGraph true &&
  11        objdir=".git/objects" &&
  12        test_oid_init
  13'
  14
  15test_expect_success 'verify graph with no graph file' '
  16        cd "$TRASH_DIRECTORY/full" &&
  17        git commit-graph verify
  18'
  19
  20test_expect_success 'write graph with no packs' '
  21        cd "$TRASH_DIRECTORY/full" &&
  22        git commit-graph write --object-dir . &&
  23        test_path_is_missing info/commit-graph
  24'
  25
  26test_expect_success 'exit with correct error on bad input to --stdin-packs' '
  27        cd "$TRASH_DIRECTORY/full" &&
  28        echo doesnotexist >in &&
  29        test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
  30        test_i18ngrep "error adding pack" stderr
  31'
  32
  33test_expect_success 'create commits and repack' '
  34        cd "$TRASH_DIRECTORY/full" &&
  35        for i in $(test_seq 3)
  36        do
  37                test_commit $i &&
  38                git branch commits/$i
  39        done &&
  40        git repack
  41'
  42
  43test_expect_success 'exit with correct error on bad input to --stdin-commits' '
  44        cd "$TRASH_DIRECTORY/full" &&
  45        echo HEAD | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr &&
  46        test_i18ngrep "invalid commit object id" stderr &&
  47        # valid tree OID, but not a commit OID
  48        git rev-parse HEAD^{tree} | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr &&
  49        test_i18ngrep "invalid commit object id" stderr
  50'
  51
  52graph_git_two_modes() {
  53        git -c core.commitGraph=true $1 >output
  54        git -c core.commitGraph=false $1 >expect
  55        test_cmp expect output
  56}
  57
  58graph_git_behavior() {
  59        MSG=$1
  60        DIR=$2
  61        BRANCH=$3
  62        COMPARE=$4
  63        test_expect_success "check normal git operations: $MSG" '
  64                cd "$TRASH_DIRECTORY/$DIR" &&
  65                graph_git_two_modes "log --oneline $BRANCH" &&
  66                graph_git_two_modes "log --topo-order $BRANCH" &&
  67                graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
  68                graph_git_two_modes "branch -vv" &&
  69                graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
  70        '
  71}
  72
  73graph_git_behavior 'no graph' full commits/3 commits/1
  74
  75graph_read_expect() {
  76        OPTIONAL=""
  77        NUM_CHUNKS=3
  78        if test ! -z $2
  79        then
  80                OPTIONAL=" $2"
  81                NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
  82        fi
  83        cat >expect <<- EOF
  84        header: 43475048 1 1 $NUM_CHUNKS 0
  85        num_commits: $1
  86        chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
  87        EOF
  88        git commit-graph read >output &&
  89        test_cmp expect output
  90}
  91
  92test_expect_success 'write graph' '
  93        cd "$TRASH_DIRECTORY/full" &&
  94        git commit-graph write &&
  95        test_path_is_file $objdir/info/commit-graph &&
  96        graph_read_expect "3"
  97'
  98
  99graph_git_behavior 'graph exists' full commits/3 commits/1
 100
 101test_expect_success 'Add more commits' '
 102        cd "$TRASH_DIRECTORY/full" &&
 103        git reset --hard commits/1 &&
 104        for i in $(test_seq 4 5)
 105        do
 106                test_commit $i &&
 107                git branch commits/$i
 108        done &&
 109        git reset --hard commits/2 &&
 110        for i in $(test_seq 6 7)
 111        do
 112                test_commit $i &&
 113                git branch commits/$i
 114        done &&
 115        git reset --hard commits/2 &&
 116        git merge commits/4 &&
 117        git branch merge/1 &&
 118        git reset --hard commits/4 &&
 119        git merge commits/6 &&
 120        git branch merge/2 &&
 121        git reset --hard commits/3 &&
 122        git merge commits/5 commits/7 &&
 123        git branch merge/3 &&
 124        git repack
 125'
 126
 127# Current graph structure:
 128#
 129#   __M3___
 130#  /   |   \
 131# 3 M1 5 M2 7
 132# |/  \|/  \|
 133# 2    4    6
 134# |___/____/
 135# 1
 136
 137test_expect_success 'write graph with merges' '
 138        cd "$TRASH_DIRECTORY/full" &&
 139        git commit-graph write &&
 140        test_path_is_file $objdir/info/commit-graph &&
 141        graph_read_expect "10" "extra_edges"
 142'
 143
 144graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
 145graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
 146graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
 147
 148test_expect_success 'Add one more commit' '
 149        cd "$TRASH_DIRECTORY/full" &&
 150        test_commit 8 &&
 151        git branch commits/8 &&
 152        ls $objdir/pack | grep idx >existing-idx &&
 153        git repack &&
 154        ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
 155'
 156
 157# Current graph structure:
 158#
 159#      8
 160#      |
 161#   __M3___
 162#  /   |   \
 163# 3 M1 5 M2 7
 164# |/  \|/  \|
 165# 2    4    6
 166# |___/____/
 167# 1
 168
 169graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
 170graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
 171
 172test_expect_success 'write graph with new commit' '
 173        cd "$TRASH_DIRECTORY/full" &&
 174        git commit-graph write &&
 175        test_path_is_file $objdir/info/commit-graph &&
 176        graph_read_expect "11" "extra_edges"
 177'
 178
 179graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
 180graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
 181
 182test_expect_success 'write graph with nothing new' '
 183        cd "$TRASH_DIRECTORY/full" &&
 184        git commit-graph write &&
 185        test_path_is_file $objdir/info/commit-graph &&
 186        graph_read_expect "11" "extra_edges"
 187'
 188
 189graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
 190graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
 191
 192test_expect_success 'build graph from latest pack with closure' '
 193        cd "$TRASH_DIRECTORY/full" &&
 194        cat new-idx | git commit-graph write --stdin-packs &&
 195        test_path_is_file $objdir/info/commit-graph &&
 196        graph_read_expect "9" "extra_edges"
 197'
 198
 199graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
 200graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
 201
 202test_expect_success 'build graph from commits with closure' '
 203        cd "$TRASH_DIRECTORY/full" &&
 204        git tag -a -m "merge" tag/merge merge/2 &&
 205        git rev-parse tag/merge >commits-in &&
 206        git rev-parse merge/1 >>commits-in &&
 207        cat commits-in | git commit-graph write --stdin-commits &&
 208        test_path_is_file $objdir/info/commit-graph &&
 209        graph_read_expect "6"
 210'
 211
 212graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
 213graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
 214
 215test_expect_success 'build graph from commits with append' '
 216        cd "$TRASH_DIRECTORY/full" &&
 217        git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
 218        test_path_is_file $objdir/info/commit-graph &&
 219        graph_read_expect "10" "extra_edges"
 220'
 221
 222graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
 223graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
 224
 225test_expect_success 'build graph using --reachable' '
 226        cd "$TRASH_DIRECTORY/full" &&
 227        git commit-graph write --reachable &&
 228        test_path_is_file $objdir/info/commit-graph &&
 229        graph_read_expect "11" "extra_edges"
 230'
 231
 232graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
 233graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
 234
 235test_expect_success 'setup bare repo' '
 236        cd "$TRASH_DIRECTORY" &&
 237        git clone --bare --no-local full bare &&
 238        cd bare &&
 239        git config core.commitGraph true &&
 240        baredir="./objects"
 241'
 242
 243graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
 244graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
 245
 246test_expect_success 'write graph in bare repo' '
 247        cd "$TRASH_DIRECTORY/bare" &&
 248        git commit-graph write &&
 249        test_path_is_file $baredir/info/commit-graph &&
 250        graph_read_expect "11" "extra_edges"
 251'
 252
 253graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
 254graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
 255
 256test_expect_success 'perform fast-forward merge in full repo' '
 257        cd "$TRASH_DIRECTORY/full" &&
 258        git checkout -b merge-5-to-8 commits/5 &&
 259        git merge commits/8 &&
 260        git show-ref -s merge-5-to-8 >output &&
 261        git show-ref -s commits/8 >expect &&
 262        test_cmp expect output
 263'
 264
 265test_expect_success 'check that gc computes commit-graph' '
 266        cd "$TRASH_DIRECTORY/full" &&
 267        git commit --allow-empty -m "blank" &&
 268        git commit-graph write --reachable &&
 269        cp $objdir/info/commit-graph commit-graph-before-gc &&
 270        git reset --hard HEAD~1 &&
 271        git config gc.writeCommitGraph true &&
 272        git gc &&
 273        cp $objdir/info/commit-graph commit-graph-after-gc &&
 274        ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
 275        git commit-graph write --reachable &&
 276        test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
 277'
 278
 279test_expect_success 'replace-objects invalidates commit-graph' '
 280        cd "$TRASH_DIRECTORY" &&
 281        test_when_finished rm -rf replace &&
 282        git clone full replace &&
 283        (
 284                cd replace &&
 285                git commit-graph write --reachable &&
 286                test_path_is_file .git/objects/info/commit-graph &&
 287                git replace HEAD~1 HEAD~2 &&
 288                git -c core.commitGraph=false log >expect &&
 289                git -c core.commitGraph=true log >actual &&
 290                test_cmp expect actual &&
 291                git commit-graph write --reachable &&
 292                git -c core.commitGraph=false --no-replace-objects log >expect &&
 293                git -c core.commitGraph=true --no-replace-objects log >actual &&
 294                test_cmp expect actual &&
 295                rm -rf .git/objects/info/commit-graph &&
 296                git commit-graph write --reachable &&
 297                test_path_is_file .git/objects/info/commit-graph
 298        )
 299'
 300
 301test_expect_success 'commit grafts invalidate commit-graph' '
 302        cd "$TRASH_DIRECTORY" &&
 303        test_when_finished rm -rf graft &&
 304        git clone full graft &&
 305        (
 306                cd graft &&
 307                git commit-graph write --reachable &&
 308                test_path_is_file .git/objects/info/commit-graph &&
 309                H1=$(git rev-parse --verify HEAD~1) &&
 310                H3=$(git rev-parse --verify HEAD~3) &&
 311                echo "$H1 $H3" >.git/info/grafts &&
 312                git -c core.commitGraph=false log >expect &&
 313                git -c core.commitGraph=true log >actual &&
 314                test_cmp expect actual &&
 315                git commit-graph write --reachable &&
 316                git -c core.commitGraph=false --no-replace-objects log >expect &&
 317                git -c core.commitGraph=true --no-replace-objects log >actual &&
 318                test_cmp expect actual &&
 319                rm -rf .git/objects/info/commit-graph &&
 320                git commit-graph write --reachable &&
 321                test_path_is_missing .git/objects/info/commit-graph
 322        )
 323'
 324
 325test_expect_success 'replace-objects invalidates commit-graph' '
 326        cd "$TRASH_DIRECTORY" &&
 327        test_when_finished rm -rf shallow &&
 328        git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
 329        (
 330                cd shallow &&
 331                git commit-graph write --reachable &&
 332                test_path_is_missing .git/objects/info/commit-graph &&
 333                git fetch origin --unshallow &&
 334                git commit-graph write --reachable &&
 335                test_path_is_file .git/objects/info/commit-graph
 336        )
 337'
 338
 339# the verify tests below expect the commit-graph to contain
 340# exactly the commits reachable from the commits/8 branch.
 341# If the file changes the set of commits in the list, then the
 342# offsets into the binary file will result in different edits
 343# and the tests will likely break.
 344
 345test_expect_success 'git commit-graph verify' '
 346        cd "$TRASH_DIRECTORY/full" &&
 347        git rev-parse commits/8 | git commit-graph write --stdin-commits &&
 348        git commit-graph verify >output
 349'
 350
 351NUM_COMMITS=9
 352NUM_OCTOPUS_EDGES=2
 353HASH_LEN="$(test_oid rawsz)"
 354GRAPH_BYTE_VERSION=4
 355GRAPH_BYTE_HASH=5
 356GRAPH_BYTE_CHUNK_COUNT=6
 357GRAPH_CHUNK_LOOKUP_OFFSET=8
 358GRAPH_CHUNK_LOOKUP_WIDTH=12
 359GRAPH_CHUNK_LOOKUP_ROWS=5
 360GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
 361GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
 362                            1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
 363GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
 364                             2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
 365GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
 366                       $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
 367GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
 368GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
 369GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
 370GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
 371GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
 372GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
 373GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
 374GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
 375GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
 376GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
 377GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
 378GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
 379GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
 380GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
 381                             $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
 382GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
 383GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
 384
 385corrupt_graph_setup() {
 386        cd "$TRASH_DIRECTORY/full" &&
 387        test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
 388        cp $objdir/info/commit-graph commit-graph-backup
 389}
 390
 391corrupt_graph_verify() {
 392        grepstr=$1
 393        test_must_fail git commit-graph verify 2>test_err &&
 394        grep -v "^+" test_err >err &&
 395        test_i18ngrep "$grepstr" err &&
 396        if test "$2" != "no-copy"
 397        then
 398                cp $objdir/info/commit-graph commit-graph-pre-write-test
 399        fi &&
 400        git status --short &&
 401        GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
 402        git commit-graph verify
 403}
 404
 405# usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
 406# Manipulates the commit-graph file at the position
 407# by inserting the data, optionally zeroing the file
 408# starting at <zero_pos>, then runs 'git commit-graph verify'
 409# and places the output in the file 'err'. Test 'err' for
 410# the given string.
 411corrupt_graph_and_verify() {
 412        pos=$1
 413        data="${2:-\0}"
 414        grepstr=$3
 415        corrupt_graph_setup &&
 416        orig_size=$(wc -c < $objdir/info/commit-graph) &&
 417        zero_pos=${4:-${orig_size}} &&
 418        printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
 419        dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
 420        generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
 421        corrupt_graph_verify "$grepstr"
 422
 423}
 424
 425test_expect_success POSIXPERM,SANITY 'detect permission problem' '
 426        corrupt_graph_setup &&
 427        chmod 000 $objdir/info/commit-graph &&
 428        corrupt_graph_verify "Could not open" "no-copy"
 429'
 430
 431test_expect_success 'detect too small' '
 432        corrupt_graph_setup &&
 433        echo "a small graph" >$objdir/info/commit-graph &&
 434        corrupt_graph_verify "too small"
 435'
 436
 437test_expect_success 'detect bad signature' '
 438        corrupt_graph_and_verify 0 "\0" \
 439                "graph signature"
 440'
 441
 442test_expect_success 'detect bad version' '
 443        corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
 444                "graph version"
 445'
 446
 447test_expect_success 'detect bad hash version' '
 448        corrupt_graph_and_verify $GRAPH_BYTE_HASH "\02" \
 449                "hash version"
 450'
 451
 452test_expect_success 'detect low chunk count' '
 453        corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
 454                "missing the .* chunk"
 455'
 456
 457test_expect_success 'detect missing OID fanout chunk' '
 458        corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
 459                "missing the OID Fanout chunk"
 460'
 461
 462test_expect_success 'detect missing OID lookup chunk' '
 463        corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
 464                "missing the OID Lookup chunk"
 465'
 466
 467test_expect_success 'detect missing commit data chunk' '
 468        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
 469                "missing the Commit Data chunk"
 470'
 471
 472test_expect_success 'detect incorrect fanout' '
 473        corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
 474                "fanout value"
 475'
 476
 477test_expect_success 'detect incorrect fanout final value' '
 478        corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
 479                "fanout value"
 480'
 481
 482test_expect_success 'detect incorrect OID order' '
 483        corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
 484                "incorrect OID order"
 485'
 486
 487test_expect_success 'detect OID not in object database' '
 488        corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
 489                "from object database"
 490'
 491
 492test_expect_success 'detect incorrect tree OID' '
 493        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
 494                "root tree OID for commit"
 495'
 496
 497test_expect_success 'detect incorrect parent int-id' '
 498        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
 499                "invalid parent"
 500'
 501
 502test_expect_success 'detect extra parent int-id' '
 503        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
 504                "is too long"
 505'
 506
 507test_expect_success 'detect wrong parent' '
 508        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
 509                "commit-graph parent for"
 510'
 511
 512test_expect_success 'detect incorrect generation number' '
 513        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
 514                "generation for commit"
 515'
 516
 517test_expect_success 'detect incorrect generation number' '
 518        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
 519                "non-zero generation number"
 520'
 521
 522test_expect_success 'detect incorrect commit date' '
 523        corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
 524                "commit date"
 525'
 526
 527test_expect_success 'detect incorrect parent for octopus merge' '
 528        corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
 529                "invalid parent"
 530'
 531
 532test_expect_success 'detect invalid checksum hash' '
 533        corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
 534                "incorrect checksum"
 535'
 536
 537test_expect_success 'detect incorrect chunk count' '
 538        corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
 539                "chunk lookup table entry missing" $GRAPH_CHUNK_LOOKUP_OFFSET
 540'
 541
 542test_expect_success 'git fsck (checks commit-graph)' '
 543        cd "$TRASH_DIRECTORY/full" &&
 544        git fsck &&
 545        corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
 546                "incorrect checksum" &&
 547        cp commit-graph-pre-write-test $objdir/info/commit-graph &&
 548        test_must_fail git fsck
 549'
 550
 551test_expect_success 'setup non-the_repository tests' '
 552        rm -rf repo &&
 553        git init repo &&
 554        test_commit -C repo one &&
 555        test_commit -C repo two &&
 556        git -C repo config core.commitGraph true &&
 557        git -C repo rev-parse two | \
 558                git -C repo commit-graph write --stdin-commits
 559'
 560
 561test_expect_success 'parse_commit_in_graph works for non-the_repository' '
 562        test-tool repository parse_commit_in_graph \
 563                repo/.git repo "$(git -C repo rev-parse two)" >actual &&
 564        {
 565                git -C repo log --pretty=format:"%ct " -1 &&
 566                git -C repo rev-parse one
 567        } >expect &&
 568        test_cmp expect actual &&
 569
 570        test-tool repository parse_commit_in_graph \
 571                repo/.git repo "$(git -C repo rev-parse one)" >actual &&
 572        git -C repo log --pretty="%ct" -1 one >expect &&
 573        test_cmp expect actual
 574'
 575
 576test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
 577        test-tool repository get_commit_tree_in_graph \
 578                repo/.git repo "$(git -C repo rev-parse two)" >actual &&
 579        git -C repo rev-parse two^{tree} >expect &&
 580        test_cmp expect actual &&
 581
 582        test-tool repository get_commit_tree_in_graph \
 583                repo/.git repo "$(git -C repo rev-parse one)" >actual &&
 584        git -C repo rev-parse one^{tree} >expect &&
 585        test_cmp expect actual
 586'
 587
 588test_done