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