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 14 test_cmp expect output 15 15 } 16 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. 17 24 graph_git_behavior() { 18 25 MSG=$1 19 26 DIR=$2 20 27 BRANCH=$3 21 28 COMPARE=$4 22 29 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" 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" 29 35 ' 30 36 } 31 37 32 38 graph_read_expect() { 33 39 OPTIONAL="" 34 40 NUM_CHUNKS=3 41 + DIR="." 42 + if test "$1" = -C 43 + then 44 + shift 45 + DIR="$1" 46 + shift 47 + fi 35 48 if test -n "$2" 36 49 then 37 50 OPTIONAL=" $2" ··· 47 60 then 48 61 OPTIONS=" read_generation_data" 49 62 fi 50 - cat >expect <<- EOF 63 + cat >"$DIR/expect" <<-EOF 51 64 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0 52 65 num_commits: $1 53 66 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL 54 67 options:$OPTIONS 55 68 EOF 56 - test-tool read-graph >output && 57 - test_cmp expect output 69 + ( 70 + cd "$DIR" && 71 + test-tool read-graph >output && 72 + test_cmp expect output 73 + ) 58 74 }
+172 -206
t/t5318-commit-graph.sh
··· 24 24 test_cmp expect actual 25 25 ' 26 26 27 + objdir=".git/objects" 28 + 27 29 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" 30 + git init full 33 31 ' 34 32 35 33 test_expect_success POSIXPERM 'tweak umask for modebit tests' ' ··· 37 35 ' 38 36 39 37 test_expect_success 'verify graph with no graph file' ' 40 - cd "$TRASH_DIRECTORY/full" && 41 - git commit-graph verify 38 + git -C full commit-graph verify 42 39 ' 43 40 44 41 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 42 + git -C full commit-graph write --object-dir $objdir && 43 + test_path_is_missing full/$objdir/info/commit-graph 48 44 ' 49 45 50 46 test_expect_success 'exit with correct error on bad input to --stdin-packs' ' 51 - cd "$TRASH_DIRECTORY/full" && 52 47 echo doesnotexist >in && 53 - test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr && 48 + test_expect_code 1 git -C full commit-graph write --stdin-packs \ 49 + <in 2>stderr && 54 50 test_i18ngrep "error adding pack" stderr 55 51 ' 56 52 57 53 test_expect_success 'create commits and repack' ' 58 - cd "$TRASH_DIRECTORY/full" && 59 54 for i in $(test_seq 3) 60 55 do 61 - test_commit $i && 62 - git branch commits/$i || return 1 56 + test_commit -C full $i && 57 + git -C full branch commits/$i || return 1 63 58 done && 64 - git repack 59 + git -C full repack 65 60 ' 66 61 67 62 . "$TEST_DIRECTORY"/lib-commit-graph.sh ··· 69 64 graph_git_behavior 'no graph' full commits/3 commits/1 70 65 71 66 test_expect_success 'exit with correct error on bad input to --stdin-commits' ' 72 - cd "$TRASH_DIRECTORY/full" && 73 67 # invalid, non-hex OID 74 - echo HEAD >in && 75 - test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr && 68 + echo HEAD | test_expect_code 1 git -C full commit-graph write \ 69 + --stdin-commits 2>stderr && 76 70 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr && 77 71 # non-existent OID 78 - echo $ZERO_OID >in && 79 - test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr && 72 + echo $ZERO_OID | test_expect_code 1 git -C full commit-graph write \ 73 + --stdin-commits 2>stderr && 80 74 test_i18ngrep "invalid object" stderr && 81 75 # 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 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 85 79 ' 86 80 87 81 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 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 92 85 ' 93 86 94 87 test_expect_success POSIXPERM 'write graph has correct permissions' ' 95 - test_path_is_file $objdir/info/commit-graph && 88 + test_path_is_file full/$objdir/info/commit-graph && 96 89 echo "-r--r--r--" >expect && 97 - test_modebits $objdir/info/commit-graph >actual && 90 + test_modebits full/$objdir/info/commit-graph >actual && 98 91 test_cmp expect actual 99 92 ' 100 93 101 94 graph_git_behavior 'graph exists' full commits/3 commits/1 102 95 103 96 test_expect_success 'Add more commits' ' 104 - cd "$TRASH_DIRECTORY/full" && 105 - git reset --hard commits/1 && 97 + git -C full reset --hard commits/1 && 106 98 for i in $(test_seq 4 5) 107 99 do 108 - test_commit $i && 109 - git branch commits/$i || return 1 100 + test_commit -C full $i && 101 + git -C full branch commits/$i || return 1 110 102 done && 111 - git reset --hard commits/2 && 103 + git -C full reset --hard commits/2 && 112 104 for i in $(test_seq 6 7) 113 105 do 114 - test_commit $i && 115 - git branch commits/$i || return 1 106 + test_commit -C full $i && 107 + git -C full branch commits/$i || return 1 116 108 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 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 127 119 ' 128 120 129 121 test_expect_success 'commit-graph write progress off for redirected stderr' ' 130 - cd "$TRASH_DIRECTORY/full" && 131 - git commit-graph write 2>err && 122 + git -C full commit-graph write 2>err && 132 123 test_must_be_empty err 133 124 ' 134 125 135 126 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 && 127 + GIT_PROGRESS_DELAY=0 git -C full commit-graph write --progress 2>err && 138 128 test_file_not_empty err 139 129 ' 140 130 141 131 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 && 132 + git -C full commit-graph write --no-progress 2>err && 144 133 test_must_be_empty err 145 134 ' 146 135 147 136 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 && 137 + git -C full rev-parse commits/5 >in && 138 + git -C full commit-graph write --stdin-commits <in 2>err && 151 139 test_must_be_empty err 152 140 ' 153 141 154 142 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 && 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 && 158 146 test_i18ngrep "Collecting commits from input" err 159 147 ' 160 148 161 149 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 && 150 + git -C full rev-parse commits/5 >in && 151 + git -C full commit-graph write --stdin-commits --no-progress <in 2>err && 165 152 test_must_be_empty err 166 153 ' 167 154 168 155 test_expect_success 'commit-graph verify progress off for redirected stderr' ' 169 - cd "$TRASH_DIRECTORY/full" && 170 - git commit-graph verify 2>err && 156 + git -C full commit-graph verify 2>err && 171 157 test_must_be_empty err 172 158 ' 173 159 174 160 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 && 161 + GIT_PROGRESS_DELAY=0 git -C full commit-graph verify --progress 2>err && 177 162 test_file_not_empty err 178 163 ' 179 164 180 165 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 && 166 + git -C full commit-graph verify --no-progress 2>err && 183 167 test_must_be_empty err 184 168 ' 185 169 ··· 194 178 # 1 195 179 196 180 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" 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" 201 184 ' 202 185 203 186 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2 ··· 205 188 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3 206 189 207 190 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 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 214 196 ' 215 197 216 198 # Current graph structure: ··· 229 211 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2 230 212 231 213 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" 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" 236 217 ' 237 218 238 219 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1 239 220 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2 240 221 241 222 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" 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" 246 226 ' 247 227 248 228 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1 249 229 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2 250 230 251 231 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" 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" 256 235 ' 257 236 258 237 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1 259 238 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2 260 239 261 240 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" 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" 269 247 ' 270 248 271 249 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1 272 250 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2 273 251 274 252 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" 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" 279 257 ' 280 258 281 259 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 282 260 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 283 261 284 262 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" 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" 289 266 ' 290 267 291 268 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 292 269 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 293 270 294 271 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" 272 + git clone --bare --no-local full bare 300 273 ' 301 274 302 275 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1 303 276 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2 304 277 305 278 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" 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" 310 282 ' 311 283 312 284 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1 313 285 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2 314 286 315 287 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 && 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 && 321 292 test_cmp expect output 322 293 ' 323 294 324 295 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 && 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 && 333 303 ! 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 304 + git -C full commit-graph write --reachable && 305 + test_cmp_bin commit-graph-after-gc full/$objdir/info/commit-graph 336 306 ' 337 307 338 308 test_expect_success 'replace-objects invalidates commit-graph' ' 339 - cd "$TRASH_DIRECTORY" && 340 309 test_when_finished rm -rf replace && 341 310 git clone full replace && 342 311 ( ··· 359 328 ' 360 329 361 330 test_expect_success 'commit grafts invalidate commit-graph' ' 362 - cd "$TRASH_DIRECTORY" && 363 331 test_when_finished rm -rf graft && 364 332 git clone --template= full graft && 365 333 ( ··· 384 352 ' 385 353 386 354 test_expect_success 'replace-objects invalidates commit-graph' ' 387 - cd "$TRASH_DIRECTORY" && 388 355 test_when_finished rm -rf shallow && 389 356 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow && 390 357 ( ··· 427 394 ' 428 395 429 396 test_expect_success TIME_IS_64BIT,TIME_T_IS_64BIT 'lower layers have overflow chunk' ' 430 - cd "$TRASH_DIRECTORY/full" && 431 397 UNIX_EPOCH_ZERO="@0 +0000" && 432 398 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 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 448 416 ' 449 417 450 418 # the verify tests below expect the commit-graph to contain ··· 454 422 # and the tests will likely break. 455 423 456 424 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 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 461 430 ' 462 431 463 432 NUM_COMMITS=9 ··· 495 464 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES)) 496 465 497 466 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 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 502 470 } 503 471 504 472 corrupt_graph_verify() { 505 473 grepstr=$1 506 - test_must_fail git commit-graph verify 2>test_err && 474 + test_must_fail git -C full commit-graph verify 2>test_err && 507 475 grep -v "^+" test_err >err && 508 476 test_i18ngrep "$grepstr" err && 509 477 if test "$2" != "no-copy" 510 478 then 511 - cp $objdir/info/commit-graph commit-graph-pre-write-test 479 + cp full/$objdir/info/commit-graph commit-graph-pre-write-test 512 480 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 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 517 485 } 518 486 519 487 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>] ··· 527 495 data="${2:-\0}" 528 496 grepstr=$3 529 497 corrupt_graph_setup && 530 - orig_size=$(wc -c < $objdir/info/commit-graph) && 498 + orig_size=$(wc -c <full/$objdir/info/commit-graph) && 531 499 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" && 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" && 535 503 corrupt_graph_verify "$grepstr" 536 504 537 505 } 538 506 539 507 test_expect_success POSIXPERM,SANITY 'detect permission problem' ' 540 508 corrupt_graph_setup && 541 - chmod 000 $objdir/info/commit-graph && 509 + chmod 000 full/$objdir/info/commit-graph && 542 510 corrupt_graph_verify "Could not open" "no-copy" 543 511 ' 544 512 545 513 test_expect_success 'detect too small' ' 546 514 corrupt_graph_setup && 547 - echo "a small graph" >$objdir/info/commit-graph && 515 + echo "a small graph" >full/$objdir/info/commit-graph && 548 516 corrupt_graph_verify "too small" 549 517 ' 550 518 ··· 655 623 ' 656 624 657 625 test_expect_success 'git fsck (checks commit-graph when config set to true)' ' 658 - cd "$TRASH_DIRECTORY/full" && 659 - git fsck && 626 + git -C full fsck && 660 627 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 661 628 "incorrect checksum" && 662 - cp commit-graph-pre-write-test $objdir/info/commit-graph && 663 - test_must_fail git -c core.commitGraph=true fsck 629 + cp commit-graph-pre-write-test full/$objdir/info/commit-graph && 630 + test_must_fail git -C full -c core.commitGraph=true fsck 664 631 ' 665 632 666 633 test_expect_success 'git fsck (ignores commit-graph when config set to false)' ' 667 - cd "$TRASH_DIRECTORY/full" && 668 - git fsck && 634 + git -C full fsck && 669 635 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 670 636 "incorrect checksum" && 671 - cp commit-graph-pre-write-test $objdir/info/commit-graph && 672 - git -c core.commitGraph=false fsck 637 + cp commit-graph-pre-write-test full/$objdir/info/commit-graph && 638 + git -C full -c core.commitGraph=false fsck 673 639 ' 674 640 675 641 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" && 642 + test_when_finished "git -C full config core.commitGraph true" && 678 643 679 - git fsck && 644 + git -C full fsck && 680 645 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ 681 646 "incorrect checksum" && 682 - test_unconfig core.commitGraph && 683 - cp commit-graph-pre-write-test $objdir/info/commit-graph && 684 - test_must_fail git fsck 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 685 650 ' 686 651 687 652 test_expect_success 'git fsck shows commit-graph output with --progress' ' ··· 792 757 # 793 758 794 759 test_expect_success 'set up and verify repo with generation data overflow chunk' ' 795 - objdir=".git/objects" && 796 760 UNIX_EPOCH_ZERO="@0 +0000" && 797 761 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 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 + ) 821 787 ' 822 788 823 789 graph_git_behavior 'generation data overflow chunk repo' repo left right
+27 -27
t/t5328-commit-graph-64bit-time.sh
··· 37 37 graph_git_behavior 'overflow' '' HEAD~2 HEAD 38 38 39 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 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 + ) 62 63 ' 63 64 64 65 graph_git_behavior 'overflow 2' repo left right 65 66 66 67 test_expect_success 'single commit with generation data exceeding UINT32_MAX' ' 67 68 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 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 73 ' 74 74 75 75 test_done