Git fork

Merge branch 'tb/commit-graph-tests'

Test updates.

* tb/commit-graph-tests:
t/lib-commit-graph.sh: avoid sub-shell in `graph_git_behavior()`
t5328: avoid top-level directory changes
t5318: avoid top-level directory changes
t/lib-commit-graph.sh: avoid directory change in `graph_git_behavior()`
t/lib-commit-graph.sh: allow `graph_read_expect()` in sub-directories

+224 -242
+25 -9
t/lib-commit-graph.sh
··· 14 test_cmp expect output 15 } 16 17 graph_git_behavior() { 18 MSG=$1 19 DIR=$2 20 BRANCH=$3 21 COMPARE=$4 22 test_expect_success "check normal git operations: $MSG" ' 23 - cd "$TRASH_DIRECTORY/$DIR" && 24 - graph_git_two_modes "log --oneline $BRANCH" && 25 - graph_git_two_modes "log --topo-order $BRANCH" && 26 - graph_git_two_modes "log --graph $COMPARE..$BRANCH" && 27 - graph_git_two_modes "branch -vv" && 28 - graph_git_two_modes "merge-base -a $BRANCH $COMPARE" 29 ' 30 } 31 32 graph_read_expect() { 33 OPTIONAL="" 34 NUM_CHUNKS=3 35 if test -n "$2" 36 then 37 OPTIONAL=" $2" ··· 47 then 48 OPTIONS=" read_generation_data" 49 fi 50 - cat >expect <<- EOF 51 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0 52 num_commits: $1 53 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL 54 options:$OPTIONS 55 EOF 56 - test-tool read-graph >output && 57 - test_cmp expect output 58 }
··· 14 test_cmp expect output 15 } 16 17 + # graph_git_behavior <name> <directory> <branch> <compare> 18 + # 19 + # Ensures that a handful of traversal operations produce the same 20 + # results with and without the commit-graph in use. 21 + # 22 + # NOTE: it is a bug to call this function with <directory> containing 23 + # any characters in $IFS. 24 graph_git_behavior() { 25 MSG=$1 26 DIR=$2 27 BRANCH=$3 28 COMPARE=$4 29 test_expect_success "check normal git operations: $MSG" ' 30 + graph_git_two_modes "${DIR:+-C $DIR} log --oneline $BRANCH" && 31 + graph_git_two_modes "${DIR:+-C $DIR} log --topo-order $BRANCH" && 32 + graph_git_two_modes "${DIR:+-C $DIR} log --graph $COMPARE..$BRANCH" && 33 + graph_git_two_modes "${DIR:+-C $DIR} branch -vv" && 34 + graph_git_two_modes "${DIR:+-C $DIR} merge-base -a $BRANCH $COMPARE" 35 ' 36 } 37 38 graph_read_expect() { 39 OPTIONAL="" 40 NUM_CHUNKS=3 41 + DIR="." 42 + if test "$1" = -C 43 + then 44 + shift 45 + DIR="$1" 46 + shift 47 + fi 48 if test -n "$2" 49 then 50 OPTIONAL=" $2" ··· 60 then 61 OPTIONS=" read_generation_data" 62 fi 63 + cat >"$DIR/expect" <<-EOF 64 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0 65 num_commits: $1 66 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL 67 options:$OPTIONS 68 EOF 69 + ( 70 + cd "$DIR" && 71 + test-tool read-graph >output && 72 + test_cmp expect output 73 + ) 74 }
+172 -206
t/t5318-commit-graph.sh
··· 24 test_cmp expect actual 25 ' 26 27 test_expect_success 'setup full repo' ' 28 - mkdir full && 29 - cd "$TRASH_DIRECTORY/full" && 30 - git init && 31 - git config core.commitGraph true && 32 - objdir=".git/objects" 33 ' 34 35 test_expect_success POSIXPERM 'tweak umask for modebit tests' ' ··· 37 ' 38 39 test_expect_success 'verify graph with no graph file' ' 40 - cd "$TRASH_DIRECTORY/full" && 41 - git commit-graph verify 42 ' 43 44 test_expect_success 'write graph with no packs' ' 45 - cd "$TRASH_DIRECTORY/full" && 46 - git commit-graph write --object-dir $objdir && 47 - test_path_is_missing $objdir/info/commit-graph 48 ' 49 50 test_expect_success 'exit with correct error on bad input to --stdin-packs' ' 51 - cd "$TRASH_DIRECTORY/full" && 52 echo doesnotexist >in && 53 - test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr && 54 test_i18ngrep "error adding pack" stderr 55 ' 56 57 test_expect_success 'create commits and repack' ' 58 - cd "$TRASH_DIRECTORY/full" && 59 for i in $(test_seq 3) 60 do 61 - test_commit $i && 62 - git branch commits/$i || return 1 63 done && 64 - git repack 65 ' 66 67 . "$TEST_DIRECTORY"/lib-commit-graph.sh ··· 69 graph_git_behavior 'no graph' full commits/3 commits/1 70 71 test_expect_success 'exit with correct error on bad input to --stdin-commits' ' 72 - cd "$TRASH_DIRECTORY/full" && 73 # invalid, non-hex OID 74 - echo HEAD >in && 75 - test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr && 76 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr && 77 # non-existent OID 78 - echo $ZERO_OID >in && 79 - test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr && 80 test_i18ngrep "invalid object" stderr && 81 # valid commit and tree OID 82 - git rev-parse HEAD HEAD^{tree} >in && 83 - git commit-graph write --stdin-commits <in && 84 - graph_read_expect 3 generation_data 85 ' 86 87 test_expect_success 'write graph' ' 88 - cd "$TRASH_DIRECTORY/full" && 89 - git commit-graph write && 90 - test_path_is_file $objdir/info/commit-graph && 91 - graph_read_expect "3" generation_data 92 ' 93 94 test_expect_success POSIXPERM 'write graph has correct permissions' ' 95 - test_path_is_file $objdir/info/commit-graph && 96 echo "-r--r--r--" >expect && 97 - test_modebits $objdir/info/commit-graph >actual && 98 test_cmp expect actual 99 ' 100 101 graph_git_behavior 'graph exists' full commits/3 commits/1 102 103 test_expect_success 'Add more commits' ' 104 - cd "$TRASH_DIRECTORY/full" && 105 - git reset --hard commits/1 && 106 for i in $(test_seq 4 5) 107 do 108 - test_commit $i && 109 - git branch commits/$i || return 1 110 done && 111 - git reset --hard commits/2 && 112 for i in $(test_seq 6 7) 113 do 114 - test_commit $i && 115 - git branch commits/$i || return 1 116 done && 117 - git reset --hard commits/2 && 118 - git merge commits/4 && 119 - git branch merge/1 && 120 - git reset --hard commits/4 && 121 - git merge commits/6 && 122 - git branch merge/2 && 123 - git reset --hard commits/3 && 124 - git merge commits/5 commits/7 && 125 - git branch merge/3 && 126 - git repack 127 ' 128 129 test_expect_success 'commit-graph write progress off for redirected stderr' ' 130 - cd "$TRASH_DIRECTORY/full" && 131 - git commit-graph write 2>err && 132 test_must_be_empty err 133 ' 134 135 test_expect_success 'commit-graph write force progress on for stderr' ' 136 - cd "$TRASH_DIRECTORY/full" && 137 - GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err && 138 test_file_not_empty err 139 ' 140 141 test_expect_success 'commit-graph write with the --no-progress option' ' 142 - cd "$TRASH_DIRECTORY/full" && 143 - git commit-graph write --no-progress 2>err && 144 test_must_be_empty err 145 ' 146 147 test_expect_success 'commit-graph write --stdin-commits progress off for redirected stderr' ' 148 - cd "$TRASH_DIRECTORY/full" && 149 - git rev-parse commits/5 >in && 150 - git commit-graph write --stdin-commits <in 2>err && 151 test_must_be_empty err 152 ' 153 154 test_expect_success 'commit-graph write --stdin-commits force progress on for stderr' ' 155 - cd "$TRASH_DIRECTORY/full" && 156 - git rev-parse commits/5 >in && 157 - GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err && 158 test_i18ngrep "Collecting commits from input" err 159 ' 160 161 test_expect_success 'commit-graph write --stdin-commits with the --no-progress option' ' 162 - cd "$TRASH_DIRECTORY/full" && 163 - git rev-parse commits/5 >in && 164 - git commit-graph write --stdin-commits --no-progress <in 2>err && 165 test_must_be_empty err 166 ' 167 168 test_expect_success 'commit-graph verify progress off for redirected stderr' ' 169 - cd "$TRASH_DIRECTORY/full" && 170 - git commit-graph verify 2>err && 171 test_must_be_empty err 172 ' 173 174 test_expect_success 'commit-graph verify force progress on for stderr' ' 175 - cd "$TRASH_DIRECTORY/full" && 176 - GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err && 177 test_file_not_empty err 178 ' 179 180 test_expect_success 'commit-graph verify with the --no-progress option' ' 181 - cd "$TRASH_DIRECTORY/full" && 182 - git commit-graph verify --no-progress 2>err && 183 test_must_be_empty err 184 ' 185 ··· 194 # 1 195 196 test_expect_success 'write graph with merges' ' 197 - cd "$TRASH_DIRECTORY/full" && 198 - git commit-graph write && 199 - test_path_is_file $objdir/info/commit-graph && 200 - graph_read_expect "10" "generation_data extra_edges" 201 ' 202 203 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2 ··· 205 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3 206 207 test_expect_success 'Add one more commit' ' 208 - cd "$TRASH_DIRECTORY/full" && 209 - test_commit 8 && 210 - git branch commits/8 && 211 - ls $objdir/pack | grep idx >existing-idx && 212 - git repack && 213 - ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx 214 ' 215 216 # Current graph structure: ··· 229 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2 230 231 test_expect_success 'write graph with new commit' ' 232 - cd "$TRASH_DIRECTORY/full" && 233 - git commit-graph write && 234 - test_path_is_file $objdir/info/commit-graph && 235 - graph_read_expect "11" "generation_data extra_edges" 236 ' 237 238 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1 239 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2 240 241 test_expect_success 'write graph with nothing new' ' 242 - cd "$TRASH_DIRECTORY/full" && 243 - git commit-graph write && 244 - test_path_is_file $objdir/info/commit-graph && 245 - graph_read_expect "11" "generation_data extra_edges" 246 ' 247 248 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1 249 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2 250 251 test_expect_success 'build graph from latest pack with closure' ' 252 - cd "$TRASH_DIRECTORY/full" && 253 - cat new-idx | git commit-graph write --stdin-packs && 254 - test_path_is_file $objdir/info/commit-graph && 255 - graph_read_expect "9" "generation_data extra_edges" 256 ' 257 258 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1 259 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2 260 261 test_expect_success 'build graph from commits with closure' ' 262 - cd "$TRASH_DIRECTORY/full" && 263 - git tag -a -m "merge" tag/merge merge/2 && 264 - git rev-parse tag/merge >commits-in && 265 - git rev-parse merge/1 >>commits-in && 266 - cat commits-in | git commit-graph write --stdin-commits && 267 - test_path_is_file $objdir/info/commit-graph && 268 - graph_read_expect "6" "generation_data" 269 ' 270 271 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1 272 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2 273 274 test_expect_success 'build graph from commits with append' ' 275 - cd "$TRASH_DIRECTORY/full" && 276 - git rev-parse merge/3 | git commit-graph write --stdin-commits --append && 277 - test_path_is_file $objdir/info/commit-graph && 278 - graph_read_expect "10" "generation_data extra_edges" 279 ' 280 281 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 282 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 283 284 test_expect_success 'build graph using --reachable' ' 285 - cd "$TRASH_DIRECTORY/full" && 286 - git commit-graph write --reachable && 287 - test_path_is_file $objdir/info/commit-graph && 288 - graph_read_expect "11" "generation_data extra_edges" 289 ' 290 291 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 292 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 293 294 test_expect_success 'setup bare repo' ' 295 - cd "$TRASH_DIRECTORY" && 296 - git clone --bare --no-local full bare && 297 - cd bare && 298 - git config core.commitGraph true && 299 - baredir="./objects" 300 ' 301 302 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1 303 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2 304 305 test_expect_success 'write graph in bare repo' ' 306 - cd "$TRASH_DIRECTORY/bare" && 307 - git commit-graph write && 308 - test_path_is_file $baredir/info/commit-graph && 309 - graph_read_expect "11" "generation_data extra_edges" 310 ' 311 312 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1 313 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2 314 315 test_expect_success 'perform fast-forward merge in full repo' ' 316 - cd "$TRASH_DIRECTORY/full" && 317 - git checkout -b merge-5-to-8 commits/5 && 318 - git merge commits/8 && 319 - git show-ref -s merge-5-to-8 >output && 320 - git show-ref -s commits/8 >expect && 321 test_cmp expect output 322 ' 323 324 test_expect_success 'check that gc computes commit-graph' ' 325 - cd "$TRASH_DIRECTORY/full" && 326 - git commit --allow-empty -m "blank" && 327 - git commit-graph write --reachable && 328 - cp $objdir/info/commit-graph commit-graph-before-gc && 329 - git reset --hard HEAD~1 && 330 - git config gc.writeCommitGraph true && 331 - git gc && 332 - cp $objdir/info/commit-graph commit-graph-after-gc && 333 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc && 334 - git commit-graph write --reachable && 335 - test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph 336 ' 337 338 test_expect_success 'replace-objects invalidates commit-graph' ' 339 - cd "$TRASH_DIRECTORY" && 340 test_when_finished rm -rf replace && 341 git clone full replace && 342 ( ··· 359 ' 360 361 test_expect_success 'commit grafts invalidate commit-graph' ' 362 - cd "$TRASH_DIRECTORY" && 363 test_when_finished rm -rf graft && 364 git clone --template= full graft && 365 ( ··· 384 ' 385 386 test_expect_success 'replace-objects invalidates commit-graph' ' 387 - cd "$TRASH_DIRECTORY" && 388 test_when_finished rm -rf shallow && 389 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow && 390 ( ··· 427 ' 428 429 test_expect_success TIME_IS_64BIT,TIME_T_IS_64BIT 'lower layers have overflow chunk' ' 430 - cd "$TRASH_DIRECTORY/full" && 431 UNIX_EPOCH_ZERO="@0 +0000" && 432 FUTURE_DATE="@4147483646 +0000" && 433 - rm -f .git/objects/info/commit-graph && 434 - test_commit --date "$FUTURE_DATE" future-1 && 435 - test_commit --date "$UNIX_EPOCH_ZERO" old-1 && 436 - git commit-graph write --reachable && 437 - test_commit --date "$FUTURE_DATE" future-2 && 438 - test_commit --date "$UNIX_EPOCH_ZERO" old-2 && 439 - git commit-graph write --reachable --split=no-merge && 440 - test_commit extra && 441 - git commit-graph write --reachable --split=no-merge && 442 - git commit-graph write --reachable && 443 - graph_read_expect 16 "generation_data generation_data_overflow extra_edges" && 444 - mv .git/objects/info/commit-graph commit-graph-upgraded && 445 - git commit-graph write --reachable && 446 - graph_read_expect 16 "generation_data generation_data_overflow extra_edges" && 447 - test_cmp .git/objects/info/commit-graph commit-graph-upgraded 448 ' 449 450 # the verify tests below expect the commit-graph to contain ··· 454 # and the tests will likely break. 455 456 test_expect_success 'git commit-graph verify' ' 457 - cd "$TRASH_DIRECTORY/full" && 458 - git rev-parse commits/8 | git -c commitGraph.generationVersion=1 commit-graph write --stdin-commits && 459 - git commit-graph verify >output && 460 - graph_read_expect 9 extra_edges 1 461 ' 462 463 NUM_COMMITS=9 ··· 495 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES)) 496 497 corrupt_graph_setup() { 498 - cd "$TRASH_DIRECTORY/full" && 499 - test_when_finished mv commit-graph-backup $objdir/info/commit-graph && 500 - cp $objdir/info/commit-graph commit-graph-backup && 501 - chmod u+w $objdir/info/commit-graph 502 } 503 504 corrupt_graph_verify() { 505 grepstr=$1 506 - test_must_fail git commit-graph verify 2>test_err && 507 grep -v "^+" test_err >err && 508 test_i18ngrep "$grepstr" err && 509 if test "$2" != "no-copy" 510 then 511 - cp $objdir/info/commit-graph commit-graph-pre-write-test 512 fi && 513 - git status --short && 514 - GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git commit-graph write && 515 - chmod u+w $objdir/info/commit-graph && 516 - git commit-graph verify 517 } 518 519 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>] ··· 527 data="${2:-\0}" 528 grepstr=$3 529 corrupt_graph_setup && 530 - orig_size=$(wc -c < $objdir/info/commit-graph) && 531 zero_pos=${4:-${orig_size}} && 532 - printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc && 533 - dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null && 534 - test-tool genzeros $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" && 535 corrupt_graph_verify "$grepstr" 536 537 } 538 539 test_expect_success POSIXPERM,SANITY 'detect permission problem' ' 540 corrupt_graph_setup && 541 - chmod 000 $objdir/info/commit-graph && 542 corrupt_graph_verify "Could not open" "no-copy" 543 ' 544 545 test_expect_success 'detect too small' ' 546 corrupt_graph_setup && 547 - echo "a small graph" >$objdir/info/commit-graph && 548 corrupt_graph_verify "too small" 549 ' 550 ··· 655 ' 656 657 test_expect_success 'git fsck (checks commit-graph when config set to true)' ' 658 - cd "$TRASH_DIRECTORY/full" && 659 - git fsck && 660 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 661 "incorrect checksum" && 662 - cp commit-graph-pre-write-test $objdir/info/commit-graph && 663 - test_must_fail git -c core.commitGraph=true fsck 664 ' 665 666 test_expect_success 'git fsck (ignores commit-graph when config set to false)' ' 667 - cd "$TRASH_DIRECTORY/full" && 668 - git fsck && 669 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 670 "incorrect checksum" && 671 - cp commit-graph-pre-write-test $objdir/info/commit-graph && 672 - git -c core.commitGraph=false fsck 673 ' 674 675 test_expect_success 'git fsck (checks commit-graph when config unset)' ' 676 - cd "$TRASH_DIRECTORY/full" && 677 - test_when_finished "git config core.commitGraph true" && 678 679 - git fsck && 680 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 681 "incorrect checksum" && 682 - test_unconfig core.commitGraph && 683 - cp commit-graph-pre-write-test $objdir/info/commit-graph && 684 - test_must_fail git fsck 685 ' 686 687 test_expect_success 'git fsck shows commit-graph output with --progress' ' ··· 792 # 793 794 test_expect_success 'set up and verify repo with generation data overflow chunk' ' 795 - objdir=".git/objects" && 796 UNIX_EPOCH_ZERO="@0 +0000" && 797 FUTURE_DATE="@2147483646 +0000" && 798 - cd "$TRASH_DIRECTORY" && 799 - mkdir repo && 800 - cd repo && 801 - git init && 802 - test_commit --date "$UNIX_EPOCH_ZERO" 1 && 803 - test_commit 2 && 804 - test_commit --date "$UNIX_EPOCH_ZERO" 3 && 805 - git commit-graph write --reachable && 806 - graph_read_expect 3 generation_data && 807 - test_commit --date "$FUTURE_DATE" 4 && 808 - test_commit 5 && 809 - test_commit --date "$UNIX_EPOCH_ZERO" 6 && 810 - git branch left && 811 - git reset --hard 3 && 812 - test_commit 7 && 813 - test_commit --date "$FUTURE_DATE" 8 && 814 - test_commit 9 && 815 - git branch right && 816 - git reset --hard 3 && 817 - test_merge M left right && 818 - git commit-graph write --reachable && 819 - graph_read_expect 10 "generation_data generation_data_overflow" && 820 - git commit-graph verify 821 ' 822 823 graph_git_behavior 'generation data overflow chunk repo' repo left right
··· 24 test_cmp expect actual 25 ' 26 27 + objdir=".git/objects" 28 + 29 test_expect_success 'setup full repo' ' 30 + git init full 31 ' 32 33 test_expect_success POSIXPERM 'tweak umask for modebit tests' ' ··· 35 ' 36 37 test_expect_success 'verify graph with no graph file' ' 38 + git -C full commit-graph verify 39 ' 40 41 test_expect_success 'write graph with no packs' ' 42 + git -C full commit-graph write --object-dir $objdir && 43 + test_path_is_missing full/$objdir/info/commit-graph 44 ' 45 46 test_expect_success 'exit with correct error on bad input to --stdin-packs' ' 47 echo doesnotexist >in && 48 + test_expect_code 1 git -C full commit-graph write --stdin-packs \ 49 + <in 2>stderr && 50 test_i18ngrep "error adding pack" stderr 51 ' 52 53 test_expect_success 'create commits and repack' ' 54 for i in $(test_seq 3) 55 do 56 + test_commit -C full $i && 57 + git -C full branch commits/$i || return 1 58 done && 59 + git -C full repack 60 ' 61 62 . "$TEST_DIRECTORY"/lib-commit-graph.sh ··· 64 graph_git_behavior 'no graph' full commits/3 commits/1 65 66 test_expect_success 'exit with correct error on bad input to --stdin-commits' ' 67 # invalid, non-hex OID 68 + echo HEAD | test_expect_code 1 git -C full commit-graph write \ 69 + --stdin-commits 2>stderr && 70 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr && 71 # non-existent OID 72 + echo $ZERO_OID | test_expect_code 1 git -C full commit-graph write \ 73 + --stdin-commits 2>stderr && 74 test_i18ngrep "invalid object" stderr && 75 # valid commit and tree OID 76 + git -C full rev-parse HEAD HEAD^{tree} >in && 77 + git -C full commit-graph write --stdin-commits <in && 78 + graph_read_expect -C full 3 generation_data 79 ' 80 81 test_expect_success 'write graph' ' 82 + git -C full commit-graph write && 83 + test_path_is_file full/$objdir/info/commit-graph && 84 + graph_read_expect -C full 3 generation_data 85 ' 86 87 test_expect_success POSIXPERM 'write graph has correct permissions' ' 88 + test_path_is_file full/$objdir/info/commit-graph && 89 echo "-r--r--r--" >expect && 90 + test_modebits full/$objdir/info/commit-graph >actual && 91 test_cmp expect actual 92 ' 93 94 graph_git_behavior 'graph exists' full commits/3 commits/1 95 96 test_expect_success 'Add more commits' ' 97 + git -C full reset --hard commits/1 && 98 for i in $(test_seq 4 5) 99 do 100 + test_commit -C full $i && 101 + git -C full branch commits/$i || return 1 102 done && 103 + git -C full reset --hard commits/2 && 104 for i in $(test_seq 6 7) 105 do 106 + test_commit -C full $i && 107 + git -C full branch commits/$i || return 1 108 done && 109 + git -C full reset --hard commits/2 && 110 + git -C full merge commits/4 && 111 + git -C full branch merge/1 && 112 + git -C full reset --hard commits/4 && 113 + git -C full merge commits/6 && 114 + git -C full branch merge/2 && 115 + git -C full reset --hard commits/3 && 116 + git -C full merge commits/5 commits/7 && 117 + git -C full branch merge/3 && 118 + git -C full repack 119 ' 120 121 test_expect_success 'commit-graph write progress off for redirected stderr' ' 122 + git -C full commit-graph write 2>err && 123 test_must_be_empty err 124 ' 125 126 test_expect_success 'commit-graph write force progress on for stderr' ' 127 + GIT_PROGRESS_DELAY=0 git -C full commit-graph write --progress 2>err && 128 test_file_not_empty err 129 ' 130 131 test_expect_success 'commit-graph write with the --no-progress option' ' 132 + git -C full commit-graph write --no-progress 2>err && 133 test_must_be_empty err 134 ' 135 136 test_expect_success 'commit-graph write --stdin-commits progress off for redirected stderr' ' 137 + git -C full rev-parse commits/5 >in && 138 + git -C full commit-graph write --stdin-commits <in 2>err && 139 test_must_be_empty err 140 ' 141 142 test_expect_success 'commit-graph write --stdin-commits force progress on for stderr' ' 143 + git -C full rev-parse commits/5 >in && 144 + GIT_PROGRESS_DELAY=0 git -C full commit-graph write --stdin-commits \ 145 + --progress <in 2>err && 146 test_i18ngrep "Collecting commits from input" err 147 ' 148 149 test_expect_success 'commit-graph write --stdin-commits with the --no-progress option' ' 150 + git -C full rev-parse commits/5 >in && 151 + git -C full commit-graph write --stdin-commits --no-progress <in 2>err && 152 test_must_be_empty err 153 ' 154 155 test_expect_success 'commit-graph verify progress off for redirected stderr' ' 156 + git -C full commit-graph verify 2>err && 157 test_must_be_empty err 158 ' 159 160 test_expect_success 'commit-graph verify force progress on for stderr' ' 161 + GIT_PROGRESS_DELAY=0 git -C full commit-graph verify --progress 2>err && 162 test_file_not_empty err 163 ' 164 165 test_expect_success 'commit-graph verify with the --no-progress option' ' 166 + git -C full commit-graph verify --no-progress 2>err && 167 test_must_be_empty err 168 ' 169 ··· 178 # 1 179 180 test_expect_success 'write graph with merges' ' 181 + git -C full commit-graph write && 182 + test_path_is_file full/$objdir/info/commit-graph && 183 + graph_read_expect -C full 10 "generation_data extra_edges" 184 ' 185 186 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2 ··· 188 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3 189 190 test_expect_success 'Add one more commit' ' 191 + test_commit -C full 8 && 192 + git -C full branch commits/8 && 193 + ls full/$objdir/pack | grep idx >existing-idx && 194 + git -C full repack && 195 + ls full/$objdir/pack| grep idx | grep -v -f existing-idx >new-idx 196 ' 197 198 # Current graph structure: ··· 211 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2 212 213 test_expect_success 'write graph with new commit' ' 214 + git -C full commit-graph write && 215 + test_path_is_file full/$objdir/info/commit-graph && 216 + graph_read_expect -C full 11 "generation_data extra_edges" 217 ' 218 219 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1 220 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2 221 222 test_expect_success 'write graph with nothing new' ' 223 + git -C full commit-graph write && 224 + test_path_is_file full/$objdir/info/commit-graph && 225 + graph_read_expect -C full 11 "generation_data extra_edges" 226 ' 227 228 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1 229 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2 230 231 test_expect_success 'build graph from latest pack with closure' ' 232 + git -C full commit-graph write --stdin-packs <new-idx && 233 + test_path_is_file full/$objdir/info/commit-graph && 234 + graph_read_expect -C full 9 "generation_data extra_edges" 235 ' 236 237 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1 238 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2 239 240 test_expect_success 'build graph from commits with closure' ' 241 + git -C full tag -a -m "merge" tag/merge merge/2 && 242 + git -C full rev-parse tag/merge >commits-in && 243 + git -C full rev-parse merge/1 >>commits-in && 244 + git -C full commit-graph write --stdin-commits <commits-in && 245 + test_path_is_file full/$objdir/info/commit-graph && 246 + graph_read_expect -C full 6 "generation_data" 247 ' 248 249 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1 250 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2 251 252 test_expect_success 'build graph from commits with append' ' 253 + git -C full rev-parse merge/3 >in && 254 + git -C full commit-graph write --stdin-commits --append <in && 255 + test_path_is_file full/$objdir/info/commit-graph && 256 + graph_read_expect -C full 10 "generation_data extra_edges" 257 ' 258 259 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 260 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 261 262 test_expect_success 'build graph using --reachable' ' 263 + git -C full commit-graph write --reachable && 264 + test_path_is_file full/$objdir/info/commit-graph && 265 + graph_read_expect -C full 11 "generation_data extra_edges" 266 ' 267 268 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 269 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 270 271 test_expect_success 'setup bare repo' ' 272 + git clone --bare --no-local full bare 273 ' 274 275 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1 276 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2 277 278 test_expect_success 'write graph in bare repo' ' 279 + git -C bare commit-graph write && 280 + test_path_is_file bare/objects/info/commit-graph && 281 + graph_read_expect -C bare 11 "generation_data extra_edges" 282 ' 283 284 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1 285 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2 286 287 test_expect_success 'perform fast-forward merge in full repo' ' 288 + git -C full checkout -b merge-5-to-8 commits/5 && 289 + git -C full merge commits/8 && 290 + git -C full show-ref -s merge-5-to-8 >output && 291 + git -C full show-ref -s commits/8 >expect && 292 test_cmp expect output 293 ' 294 295 test_expect_success 'check that gc computes commit-graph' ' 296 + test_commit -C full --no-tag blank && 297 + git -C full commit-graph write --reachable && 298 + cp full/$objdir/info/commit-graph commit-graph-before-gc && 299 + git -C full reset --hard HEAD~1 && 300 + test_config -C full gc.writeCommitGraph true && 301 + git -C full gc && 302 + cp full/$objdir/info/commit-graph commit-graph-after-gc && 303 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc && 304 + git -C full commit-graph write --reachable && 305 + test_cmp_bin commit-graph-after-gc full/$objdir/info/commit-graph 306 ' 307 308 test_expect_success 'replace-objects invalidates commit-graph' ' 309 test_when_finished rm -rf replace && 310 git clone full replace && 311 ( ··· 328 ' 329 330 test_expect_success 'commit grafts invalidate commit-graph' ' 331 test_when_finished rm -rf graft && 332 git clone --template= full graft && 333 ( ··· 352 ' 353 354 test_expect_success 'replace-objects invalidates commit-graph' ' 355 test_when_finished rm -rf shallow && 356 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow && 357 ( ··· 394 ' 395 396 test_expect_success TIME_IS_64BIT,TIME_T_IS_64BIT 'lower layers have overflow chunk' ' 397 UNIX_EPOCH_ZERO="@0 +0000" && 398 FUTURE_DATE="@4147483646 +0000" && 399 + rm -f full/.git/objects/info/commit-graph && 400 + test_commit -C full --date "$FUTURE_DATE" future-1 && 401 + test_commit -C full --date "$UNIX_EPOCH_ZERO" old-1 && 402 + git -C full commit-graph write --reachable && 403 + test_commit -C full --date "$FUTURE_DATE" future-2 && 404 + test_commit -C full --date "$UNIX_EPOCH_ZERO" old-2 && 405 + git -C full commit-graph write --reachable --split=no-merge && 406 + test_commit -C full extra && 407 + git -C full commit-graph write --reachable --split=no-merge && 408 + git -C full commit-graph write --reachable && 409 + graph_read_expect -C full 16 \ 410 + "generation_data generation_data_overflow extra_edges" && 411 + mv full/.git/objects/info/commit-graph commit-graph-upgraded && 412 + git -C full commit-graph write --reachable && 413 + graph_read_expect -C full 16 \ 414 + "generation_data generation_data_overflow extra_edges" && 415 + test_cmp full/.git/objects/info/commit-graph commit-graph-upgraded 416 ' 417 418 # the verify tests below expect the commit-graph to contain ··· 422 # and the tests will likely break. 423 424 test_expect_success 'git commit-graph verify' ' 425 + git -C full rev-parse commits/8 >in && 426 + git -C full -c commitGraph.generationVersion=1 commit-graph write \ 427 + --stdin-commits <in && 428 + git -C full commit-graph verify >output && 429 + graph_read_expect -C full 9 extra_edges 1 430 ' 431 432 NUM_COMMITS=9 ··· 464 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES)) 465 466 corrupt_graph_setup() { 467 + test_when_finished mv commit-graph-backup full/$objdir/info/commit-graph && 468 + cp full/$objdir/info/commit-graph commit-graph-backup && 469 + chmod u+w full/$objdir/info/commit-graph 470 } 471 472 corrupt_graph_verify() { 473 grepstr=$1 474 + test_must_fail git -C full commit-graph verify 2>test_err && 475 grep -v "^+" test_err >err && 476 test_i18ngrep "$grepstr" err && 477 if test "$2" != "no-copy" 478 then 479 + cp full/$objdir/info/commit-graph commit-graph-pre-write-test 480 fi && 481 + git -C full status --short && 482 + GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git -C full commit-graph write && 483 + chmod u+w full/$objdir/info/commit-graph && 484 + git -C full commit-graph verify 485 } 486 487 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>] ··· 495 data="${2:-\0}" 496 grepstr=$3 497 corrupt_graph_setup && 498 + orig_size=$(wc -c <full/$objdir/info/commit-graph) && 499 zero_pos=${4:-${orig_size}} && 500 + printf "$data" | dd of="full/$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc && 501 + dd of="full/$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null && 502 + test-tool genzeros $(($orig_size - $zero_pos)) >>"full/$objdir/info/commit-graph" && 503 corrupt_graph_verify "$grepstr" 504 505 } 506 507 test_expect_success POSIXPERM,SANITY 'detect permission problem' ' 508 corrupt_graph_setup && 509 + chmod 000 full/$objdir/info/commit-graph && 510 corrupt_graph_verify "Could not open" "no-copy" 511 ' 512 513 test_expect_success 'detect too small' ' 514 corrupt_graph_setup && 515 + echo "a small graph" >full/$objdir/info/commit-graph && 516 corrupt_graph_verify "too small" 517 ' 518 ··· 623 ' 624 625 test_expect_success 'git fsck (checks commit-graph when config set to true)' ' 626 + git -C full fsck && 627 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 628 "incorrect checksum" && 629 + cp commit-graph-pre-write-test full/$objdir/info/commit-graph && 630 + test_must_fail git -C full -c core.commitGraph=true fsck 631 ' 632 633 test_expect_success 'git fsck (ignores commit-graph when config set to false)' ' 634 + git -C full fsck && 635 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 636 "incorrect checksum" && 637 + cp commit-graph-pre-write-test full/$objdir/info/commit-graph && 638 + git -C full -c core.commitGraph=false fsck 639 ' 640 641 test_expect_success 'git fsck (checks commit-graph when config unset)' ' 642 + test_when_finished "git -C full config core.commitGraph true" && 643 644 + git -C full fsck && 645 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 646 "incorrect checksum" && 647 + test_unconfig -C full core.commitGraph && 648 + cp commit-graph-pre-write-test full/$objdir/info/commit-graph && 649 + test_must_fail git -C full fsck 650 ' 651 652 test_expect_success 'git fsck shows commit-graph output with --progress' ' ··· 757 # 758 759 test_expect_success 'set up and verify repo with generation data overflow chunk' ' 760 UNIX_EPOCH_ZERO="@0 +0000" && 761 FUTURE_DATE="@2147483646 +0000" && 762 + 763 + git init repo && 764 + ( 765 + cd repo && 766 + 767 + test_commit --date "$UNIX_EPOCH_ZERO" 1 && 768 + test_commit 2 && 769 + test_commit --date "$UNIX_EPOCH_ZERO" 3 && 770 + git commit-graph write --reachable && 771 + graph_read_expect 3 generation_data && 772 + test_commit --date "$FUTURE_DATE" 4 && 773 + test_commit 5 && 774 + test_commit --date "$UNIX_EPOCH_ZERO" 6 && 775 + git branch left && 776 + git reset --hard 3 && 777 + test_commit 7 && 778 + test_commit --date "$FUTURE_DATE" 8 && 779 + test_commit 9 && 780 + git branch right && 781 + git reset --hard 3 && 782 + test_merge M left right && 783 + git commit-graph write --reachable && 784 + graph_read_expect 10 "generation_data generation_data_overflow" && 785 + git commit-graph verify 786 + ) 787 ' 788 789 graph_git_behavior 'generation data overflow chunk repo' repo left right
+27 -27
t/t5328-commit-graph-64bit-time.sh
··· 37 graph_git_behavior 'overflow' '' HEAD~2 HEAD 38 39 test_expect_success 'set up and verify repo with generation data overflow chunk' ' 40 - mkdir repo && 41 - cd repo && 42 - git init && 43 - test_commit --date "$UNIX_EPOCH_ZERO" 1 && 44 - test_commit 2 && 45 - test_commit --date "$UNIX_EPOCH_ZERO" 3 && 46 - git commit-graph write --reachable && 47 - graph_read_expect 3 generation_data && 48 - test_commit --date "$FUTURE_DATE" 4 && 49 - test_commit 5 && 50 - test_commit --date "$UNIX_EPOCH_ZERO" 6 && 51 - git branch left && 52 - git reset --hard 3 && 53 - test_commit 7 && 54 - test_commit --date "$FUTURE_DATE" 8 && 55 - test_commit 9 && 56 - git branch right && 57 - git reset --hard 3 && 58 - test_merge M left right && 59 - git commit-graph write --reachable && 60 - graph_read_expect 10 "generation_data generation_data_overflow" && 61 - git commit-graph verify 62 ' 63 64 graph_git_behavior 'overflow 2' repo left right 65 66 test_expect_success 'single commit with generation data exceeding UINT32_MAX' ' 67 git init repo-uint32-max && 68 - cd repo-uint32-max && 69 - test_commit --date "@4294967297 +0000" 1 && 70 - git commit-graph write --reachable && 71 - graph_read_expect 1 "generation_data" && 72 - git commit-graph verify 73 ' 74 75 test_done
··· 37 graph_git_behavior 'overflow' '' HEAD~2 HEAD 38 39 test_expect_success 'set up and verify repo with generation data overflow chunk' ' 40 + git init repo && 41 + ( 42 + cd repo && 43 + test_commit --date "$UNIX_EPOCH_ZERO" 1 && 44 + test_commit 2 && 45 + test_commit --date "$UNIX_EPOCH_ZERO" 3 && 46 + git commit-graph write --reachable && 47 + graph_read_expect 3 generation_data && 48 + test_commit --date "$FUTURE_DATE" 4 && 49 + test_commit 5 && 50 + test_commit --date "$UNIX_EPOCH_ZERO" 6 && 51 + git branch left && 52 + git reset --hard 3 && 53 + test_commit 7 && 54 + test_commit --date "$FUTURE_DATE" 8 && 55 + test_commit 9 && 56 + git branch right && 57 + git reset --hard 3 && 58 + test_merge M left right && 59 + git commit-graph write --reachable && 60 + graph_read_expect 10 "generation_data generation_data_overflow" && 61 + git commit-graph verify 62 + ) 63 ' 64 65 graph_git_behavior 'overflow 2' repo left right 66 67 test_expect_success 'single commit with generation data exceeding UINT32_MAX' ' 68 git init repo-uint32-max && 69 + test_commit -C repo-uint32-max --date "@4294967297 +0000" 1 && 70 + git -C repo-uint32-max commit-graph write --reachable && 71 + graph_read_expect -C repo-uint32-max 1 "generation_data" && 72 + git -C repo-uint32-max commit-graph verify 73 ' 74 75 test_done