3 test_description
='commit graph'
6 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS
=0
8 test_expect_success
'usage' '
9 test_expect_code 129 git commit-graph write blah 2>err &&
10 test_expect_code 129 git commit-graph write verify
13 test_expect_success
'usage shown without sub-command' '
14 test_expect_code 129 git commit-graph 2>err &&
18 test_expect_success
'usage shown with an error on unknown sub-command' '
19 cat >expect <<-\EOF &&
20 error: unrecognized subcommand: unknown
22 test_expect_code 129 git commit-graph unknown 2>stderr &&
23 grep error stderr >actual &&
24 test_cmp expect actual
27 test_expect_success
'setup full repo' '
29 cd "$TRASH_DIRECTORY/full" &&
31 git config core.commitGraph true &&
32 objdir=".git/objects" &&
40 test_expect_success POSIXPERM
'tweak umask for modebit tests' '
44 test_expect_success
'verify graph with no graph file' '
45 cd "$TRASH_DIRECTORY/full" &&
46 git commit-graph verify
49 test_expect_success
'write graph with no packs' '
50 cd "$TRASH_DIRECTORY/full" &&
51 git commit-graph write --object-dir $objdir &&
52 test_path_is_missing $objdir/info/commit-graph
55 test_expect_success
'exit with correct error on bad input to --stdin-packs' '
56 cd "$TRASH_DIRECTORY/full" &&
57 echo doesnotexist >in &&
58 test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
59 test_i18ngrep "error adding pack" stderr
62 test_expect_success
'create commits and repack' '
63 cd "$TRASH_DIRECTORY/full" &&
64 for i in $(test_seq 3)
72 graph_git_two_modes
() {
73 git
-c core.commitGraph
=true
$1 >output
74 git
-c core.commitGraph
=false
$1 >expect
75 test_cmp expect output
78 graph_git_behavior
() {
83 test_expect_success
"check normal git operations: $MSG" '
84 cd "$TRASH_DIRECTORY/$DIR" &&
85 graph_git_two_modes "log --oneline $BRANCH" &&
86 graph_git_two_modes "log --topo-order $BRANCH" &&
87 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
88 graph_git_two_modes "branch -vv" &&
89 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
93 graph_git_behavior
'no graph' full commits
/3 commits
/1
101 NUM_CHUNKS
=$
((3 + $
(echo "$2" |
wc -w)))
104 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
106 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
108 test-tool read-graph
>output
&&
109 test_cmp expect output
112 test_expect_success
'exit with correct error on bad input to --stdin-commits' '
113 cd "$TRASH_DIRECTORY/full" &&
114 # invalid, non-hex OID
116 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
117 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
119 echo $ZERO_OID >in &&
120 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
121 test_i18ngrep "invalid object" stderr &&
122 # valid commit and tree OID
123 git rev-parse HEAD HEAD^{tree} >in &&
124 git commit-graph write --stdin-commits <in &&
125 graph_read_expect 3 generation_data
128 test_expect_success
'write graph' '
129 cd "$TRASH_DIRECTORY/full" &&
130 git commit-graph write &&
131 test_path_is_file $objdir/info/commit-graph &&
132 graph_read_expect "3" generation_data
135 test_expect_success POSIXPERM
'write graph has correct permissions' '
136 test_path_is_file $objdir/info/commit-graph &&
137 echo "-r--r--r--" >expect &&
138 test_modebits $objdir/info/commit-graph >actual &&
139 test_cmp expect actual
142 graph_git_behavior
'graph exists' full commits
/3 commits
/1
144 test_expect_success
'Add more commits' '
145 cd "$TRASH_DIRECTORY/full" &&
146 git reset --hard commits/1 &&
147 for i in $(test_seq 4 5)
150 git branch commits/$i
152 git reset --hard commits/2 &&
153 for i in $(test_seq 6 7)
156 git branch commits/$i
158 git reset --hard commits/2 &&
159 git merge commits/4 &&
160 git branch merge/1 &&
161 git reset --hard commits/4 &&
162 git merge commits/6 &&
163 git branch merge/2 &&
164 git reset --hard commits/3 &&
165 git merge commits/5 commits/7 &&
166 git branch merge/3 &&
170 test_expect_success
'commit-graph write progress off for redirected stderr' '
171 cd "$TRASH_DIRECTORY/full" &&
172 git commit-graph write 2>err &&
173 test_must_be_empty err
176 test_expect_success
'commit-graph write force progress on for stderr' '
177 cd "$TRASH_DIRECTORY/full" &&
178 GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
179 test_file_not_empty err
182 test_expect_success
'commit-graph write with the --no-progress option' '
183 cd "$TRASH_DIRECTORY/full" &&
184 git commit-graph write --no-progress 2>err &&
185 test_must_be_empty err
188 test_expect_success
'commit-graph write --stdin-commits progress off for redirected stderr' '
189 cd "$TRASH_DIRECTORY/full" &&
190 git rev-parse commits/5 >in &&
191 git commit-graph write --stdin-commits <in 2>err &&
192 test_must_be_empty err
195 test_expect_success
'commit-graph write --stdin-commits force progress on for stderr' '
196 cd "$TRASH_DIRECTORY/full" &&
197 git rev-parse commits/5 >in &&
198 GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err &&
199 test_i18ngrep "Collecting commits from input" err
202 test_expect_success
'commit-graph write --stdin-commits with the --no-progress option' '
203 cd "$TRASH_DIRECTORY/full" &&
204 git rev-parse commits/5 >in &&
205 git commit-graph write --stdin-commits --no-progress <in 2>err &&
206 test_must_be_empty err
209 test_expect_success
'commit-graph verify progress off for redirected stderr' '
210 cd "$TRASH_DIRECTORY/full" &&
211 git commit-graph verify 2>err &&
212 test_must_be_empty err
215 test_expect_success
'commit-graph verify force progress on for stderr' '
216 cd "$TRASH_DIRECTORY/full" &&
217 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
218 test_file_not_empty err
221 test_expect_success
'commit-graph verify with the --no-progress option' '
222 cd "$TRASH_DIRECTORY/full" &&
223 git commit-graph verify --no-progress 2>err &&
224 test_must_be_empty err
227 # Current graph structure:
237 test_expect_success
'write graph with merges' '
238 cd "$TRASH_DIRECTORY/full" &&
239 git commit-graph write &&
240 test_path_is_file $objdir/info/commit-graph &&
241 graph_read_expect "10" "generation_data extra_edges"
244 graph_git_behavior
'merge 1 vs 2' full merge
/1 merge
/2
245 graph_git_behavior
'merge 1 vs 3' full merge
/1 merge
/3
246 graph_git_behavior
'merge 2 vs 3' full merge
/2 merge
/3
248 test_expect_success
'Add one more commit' '
249 cd "$TRASH_DIRECTORY/full" &&
251 git branch commits/8 &&
252 ls $objdir/pack | grep idx >existing-idx &&
254 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
257 # Current graph structure:
269 graph_git_behavior
'mixed mode, commit 8 vs merge 1' full commits
/8 merge
/1
270 graph_git_behavior
'mixed mode, commit 8 vs merge 2' full commits
/8 merge
/2
272 test_expect_success
'write graph with new commit' '
273 cd "$TRASH_DIRECTORY/full" &&
274 git commit-graph write &&
275 test_path_is_file $objdir/info/commit-graph &&
276 graph_read_expect "11" "generation_data extra_edges"
279 graph_git_behavior
'full graph, commit 8 vs merge 1' full commits
/8 merge
/1
280 graph_git_behavior
'full graph, commit 8 vs merge 2' full commits
/8 merge
/2
282 test_expect_success
'write graph with nothing new' '
283 cd "$TRASH_DIRECTORY/full" &&
284 git commit-graph write &&
285 test_path_is_file $objdir/info/commit-graph &&
286 graph_read_expect "11" "generation_data extra_edges"
289 graph_git_behavior
'cleared graph, commit 8 vs merge 1' full commits
/8 merge
/1
290 graph_git_behavior
'cleared graph, commit 8 vs merge 2' full commits
/8 merge
/2
292 test_expect_success
'build graph from latest pack with closure' '
293 cd "$TRASH_DIRECTORY/full" &&
294 cat new-idx | git commit-graph write --stdin-packs &&
295 test_path_is_file $objdir/info/commit-graph &&
296 graph_read_expect "9" "generation_data extra_edges"
299 graph_git_behavior
'graph from pack, commit 8 vs merge 1' full commits
/8 merge
/1
300 graph_git_behavior
'graph from pack, commit 8 vs merge 2' full commits
/8 merge
/2
302 test_expect_success
'build graph from commits with closure' '
303 cd "$TRASH_DIRECTORY/full" &&
304 git tag -a -m "merge" tag/merge merge/2 &&
305 git rev-parse tag/merge >commits-in &&
306 git rev-parse merge/1 >>commits-in &&
307 cat commits-in | git commit-graph write --stdin-commits &&
308 test_path_is_file $objdir/info/commit-graph &&
309 graph_read_expect "6" "generation_data"
312 graph_git_behavior
'graph from commits, commit 8 vs merge 1' full commits
/8 merge
/1
313 graph_git_behavior
'graph from commits, commit 8 vs merge 2' full commits
/8 merge
/2
315 test_expect_success
'build graph from commits with append' '
316 cd "$TRASH_DIRECTORY/full" &&
317 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
318 test_path_is_file $objdir/info/commit-graph &&
319 graph_read_expect "10" "generation_data extra_edges"
322 graph_git_behavior
'append graph, commit 8 vs merge 1' full commits
/8 merge
/1
323 graph_git_behavior
'append graph, commit 8 vs merge 2' full commits
/8 merge
/2
325 test_expect_success
'build graph using --reachable' '
326 cd "$TRASH_DIRECTORY/full" &&
327 git commit-graph write --reachable &&
328 test_path_is_file $objdir/info/commit-graph &&
329 graph_read_expect "11" "generation_data extra_edges"
332 graph_git_behavior
'append graph, commit 8 vs merge 1' full commits
/8 merge
/1
333 graph_git_behavior
'append graph, commit 8 vs merge 2' full commits
/8 merge
/2
335 test_expect_success
'setup bare repo' '
336 cd "$TRASH_DIRECTORY" &&
337 git clone --bare --no-local full bare &&
339 git config core.commitGraph true &&
343 graph_git_behavior
'bare repo, commit 8 vs merge 1' bare commits
/8 merge
/1
344 graph_git_behavior
'bare repo, commit 8 vs merge 2' bare commits
/8 merge
/2
346 test_expect_success
'write graph in bare repo' '
347 cd "$TRASH_DIRECTORY/bare" &&
348 git commit-graph write &&
349 test_path_is_file $baredir/info/commit-graph &&
350 graph_read_expect "11" "generation_data extra_edges"
353 graph_git_behavior
'bare repo with graph, commit 8 vs merge 1' bare commits
/8 merge
/1
354 graph_git_behavior
'bare repo with graph, commit 8 vs merge 2' bare commits
/8 merge
/2
356 test_expect_success
'perform fast-forward merge in full repo' '
357 cd "$TRASH_DIRECTORY/full" &&
358 git checkout -b merge-5-to-8 commits/5 &&
359 git merge commits/8 &&
360 git show-ref -s merge-5-to-8 >output &&
361 git show-ref -s commits/8 >expect &&
362 test_cmp expect output
365 test_expect_success
'check that gc computes commit-graph' '
366 cd "$TRASH_DIRECTORY/full" &&
367 git commit --allow-empty -m "blank" &&
368 git commit-graph write --reachable &&
369 cp $objdir/info/commit-graph commit-graph-before-gc &&
370 git reset --hard HEAD~1 &&
371 git config gc.writeCommitGraph true &&
373 cp $objdir/info/commit-graph commit-graph-after-gc &&
374 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
375 git commit-graph write --reachable &&
376 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
379 test_expect_success
'replace-objects invalidates commit-graph' '
380 cd "$TRASH_DIRECTORY" &&
381 test_when_finished rm -rf replace &&
382 git clone full replace &&
385 git commit-graph write --reachable &&
386 test_path_is_file .git/objects/info/commit-graph &&
387 git replace HEAD~1 HEAD~2 &&
388 git -c core.commitGraph=false log >expect &&
389 git -c core.commitGraph=true log >actual &&
390 test_cmp expect actual &&
391 git commit-graph write --reachable &&
392 git -c core.commitGraph=false --no-replace-objects log >expect &&
393 git -c core.commitGraph=true --no-replace-objects log >actual &&
394 test_cmp expect actual &&
395 rm -rf .git/objects/info/commit-graph &&
396 git commit-graph write --reachable &&
397 test_path_is_file .git/objects/info/commit-graph
401 test_expect_success
'commit grafts invalidate commit-graph' '
402 cd "$TRASH_DIRECTORY" &&
403 test_when_finished rm -rf graft &&
404 git clone full graft &&
407 git commit-graph write --reachable &&
408 test_path_is_file .git/objects/info/commit-graph &&
409 H1=$(git rev-parse --verify HEAD~1) &&
410 H3=$(git rev-parse --verify HEAD~3) &&
411 echo "$H1 $H3" >.git/info/grafts &&
412 git -c core.commitGraph=false log >expect &&
413 git -c core.commitGraph=true log >actual &&
414 test_cmp expect actual &&
415 git commit-graph write --reachable &&
416 git -c core.commitGraph=false --no-replace-objects log >expect &&
417 git -c core.commitGraph=true --no-replace-objects log >actual &&
418 test_cmp expect actual &&
419 rm -rf .git/objects/info/commit-graph &&
420 git commit-graph write --reachable &&
421 test_path_is_missing .git/objects/info/commit-graph
425 test_expect_success
'replace-objects invalidates commit-graph' '
426 cd "$TRASH_DIRECTORY" &&
427 test_when_finished rm -rf shallow &&
428 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
431 git commit-graph write --reachable &&
432 test_path_is_missing .git/objects/info/commit-graph &&
433 git fetch origin --unshallow &&
434 git commit-graph write --reachable &&
435 test_path_is_file .git/objects/info/commit-graph
439 test_expect_success
'warn on improper hash version' '
440 git init --object-format=sha1 sha1 &&
444 git commit-graph write --reachable &&
445 mv .git/objects/info/commit-graph ../cg-sha1
447 git init --object-format=sha256 sha256 &&
451 git commit-graph write --reachable &&
452 mv .git/objects/info/commit-graph ../cg-sha256
456 mv ../cg-sha256 .git/objects/info/commit-graph &&
458 test_i18ngrep "commit-graph hash version 2 does not match version 1" err
462 mv ../cg-sha1 .git/objects/info/commit-graph &&
464 test_i18ngrep "commit-graph hash version 1 does not match version 2" err
468 test_expect_success
'lower layers have overflow chunk' '
469 cd "$TRASH_DIRECTORY/full" &&
470 UNIX_EPOCH_ZERO="@0 +0000" &&
471 FUTURE_DATE="@2147483646 +0000" &&
472 rm -f .git/objects/info/commit-graph &&
473 test_commit --date "$FUTURE_DATE" future-1 &&
474 test_commit --date "$UNIX_EPOCH_ZERO" old-1 &&
475 git commit-graph write --reachable &&
476 test_commit --date "$FUTURE_DATE" future-2 &&
477 test_commit --date "$UNIX_EPOCH_ZERO" old-2 &&
478 git commit-graph write --reachable --split=no-merge &&
480 git commit-graph write --reachable --split=no-merge &&
481 git commit-graph write --reachable &&
482 graph_read_expect 16 "generation_data generation_data_overflow extra_edges" &&
483 mv .git/objects/info/commit-graph commit-graph-upgraded &&
484 git commit-graph write --reachable &&
485 graph_read_expect 16 "generation_data generation_data_overflow extra_edges" &&
486 test_cmp .git/objects/info/commit-graph commit-graph-upgraded
489 # the verify tests below expect the commit-graph to contain
490 # exactly the commits reachable from the commits/8 branch.
491 # If the file changes the set of commits in the list, then the
492 # offsets into the binary file will result in different edits
493 # and the tests will likely break.
495 test_expect_success
'git commit-graph verify' '
496 cd "$TRASH_DIRECTORY/full" &&
497 git rev-parse commits/8 | git -c commitGraph.generationVersion=1 commit-graph write --stdin-commits &&
498 git commit-graph verify >output &&
499 graph_read_expect 9 extra_edges
504 HASH_LEN
="$(test_oid rawsz)"
507 GRAPH_BYTE_CHUNK_COUNT
=6
508 GRAPH_CHUNK_LOOKUP_OFFSET
=8
509 GRAPH_CHUNK_LOOKUP_WIDTH
=12
510 GRAPH_CHUNK_LOOKUP_ROWS
=5
511 GRAPH_BYTE_OID_FANOUT_ID
=$GRAPH_CHUNK_LOOKUP_OFFSET
512 GRAPH_BYTE_OID_LOOKUP_ID
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
513 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
514 GRAPH_BYTE_COMMIT_DATA_ID
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
515 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
516 GRAPH_FANOUT_OFFSET
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
517 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
518 GRAPH_BYTE_FANOUT1
=$
(($GRAPH_FANOUT_OFFSET + 4 * 4))
519 GRAPH_BYTE_FANOUT2
=$
(($GRAPH_FANOUT_OFFSET + 4 * 255))
520 GRAPH_OID_LOOKUP_OFFSET
=$
(($GRAPH_FANOUT_OFFSET + 4 * 256))
521 GRAPH_BYTE_OID_LOOKUP_ORDER
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
522 GRAPH_BYTE_OID_LOOKUP_MISSING
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
523 GRAPH_COMMIT_DATA_OFFSET
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
524 GRAPH_BYTE_COMMIT_TREE
=$GRAPH_COMMIT_DATA_OFFSET
525 GRAPH_BYTE_COMMIT_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
526 GRAPH_BYTE_COMMIT_EXTRA_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
527 GRAPH_BYTE_COMMIT_WRONG_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
528 GRAPH_BYTE_COMMIT_GENERATION
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
529 GRAPH_BYTE_COMMIT_DATE
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
530 GRAPH_COMMIT_DATA_WIDTH
=$
(($HASH_LEN + 16))
531 GRAPH_OCTOPUS_DATA_OFFSET
=$
(($GRAPH_COMMIT_DATA_OFFSET + \
532 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
533 GRAPH_BYTE_OCTOPUS
=$
(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
534 GRAPH_BYTE_FOOTER
=$
(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
536 corrupt_graph_setup
() {
537 cd "$TRASH_DIRECTORY/full" &&
538 test_when_finished
mv commit-graph-backup
$objdir/info
/commit-graph
&&
539 cp $objdir/info
/commit-graph commit-graph-backup
&&
540 chmod u
+w
$objdir/info
/commit-graph
543 corrupt_graph_verify
() {
545 test_must_fail git commit-graph verify
2>test_err
&&
546 grep -v "^+" test_err
>err
&&
547 test_i18ngrep
"$grepstr" err
&&
548 if test "$2" != "no-copy"
550 cp $objdir/info
/commit-graph commit-graph-pre-write-test
552 git status
--short &&
553 GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE
=true git commit-graph
write &&
554 chmod u
+w
$objdir/info
/commit-graph
&&
555 git commit-graph verify
558 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
559 # Manipulates the commit-graph file at the position
560 # by inserting the data, optionally zeroing the file
561 # starting at <zero_pos>, then runs 'git commit-graph verify'
562 # and places the output in the file 'err'. Test 'err' for
564 corrupt_graph_and_verify
() {
568 corrupt_graph_setup
&&
569 orig_size
=$
(wc -c < $objdir/info
/commit-graph
) &&
570 zero_pos
=${4:-${orig_size}} &&
571 printf "$data" |
dd of
="$objdir/info/commit-graph" bs
=1 seek
="$pos" conv
=notrunc
&&
572 dd of
="$objdir/info/commit-graph" bs
=1 seek
="$zero_pos" if=/dev
/null
&&
573 test-tool genzeros $
(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
574 corrupt_graph_verify
"$grepstr"
578 test_expect_success POSIXPERM
,SANITY
'detect permission problem' '
579 corrupt_graph_setup &&
580 chmod 000 $objdir/info/commit-graph &&
581 corrupt_graph_verify "Could not open" "no-copy"
584 test_expect_success
'detect too small' '
585 corrupt_graph_setup &&
586 echo "a small graph" >$objdir/info/commit-graph &&
587 corrupt_graph_verify "too small"
590 test_expect_success
'detect bad signature' '
591 corrupt_graph_and_verify 0 "\0" \
595 test_expect_success
'detect bad version' '
596 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
600 test_expect_success
'detect bad hash version' '
601 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
605 test_expect_success
'detect low chunk count' '
606 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\01" \
607 "final chunk has non-zero id"
610 test_expect_success
'detect missing OID fanout chunk' '
611 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
612 "missing the OID Fanout chunk"
615 test_expect_success
'detect missing OID lookup chunk' '
616 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
617 "missing the OID Lookup chunk"
620 test_expect_success
'detect missing commit data chunk' '
621 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
622 "missing the Commit Data chunk"
625 test_expect_success
'detect incorrect fanout' '
626 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
630 test_expect_success
'detect incorrect fanout final value' '
631 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
635 test_expect_success
'detect incorrect OID order' '
636 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
637 "incorrect OID order"
640 test_expect_success
'detect OID not in object database' '
641 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
642 "from object database"
645 test_expect_success
'detect incorrect tree OID' '
646 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
647 "root tree OID for commit"
650 test_expect_success
'detect incorrect parent int-id' '
651 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
655 test_expect_success
'detect extra parent int-id' '
656 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
660 test_expect_success
'detect wrong parent' '
661 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
662 "commit-graph parent for"
665 test_expect_success
'detect incorrect generation number' '
666 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
667 "generation for commit"
670 test_expect_success
'detect incorrect generation number' '
671 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
672 "non-zero generation number"
675 test_expect_success
'detect incorrect commit date' '
676 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
680 test_expect_success
'detect incorrect parent for octopus merge' '
681 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
685 test_expect_success
'detect invalid checksum hash' '
686 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
690 test_expect_success
'detect incorrect chunk count' '
691 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
692 "commit-graph file is too small to hold [0-9]* chunks" \
693 $GRAPH_CHUNK_LOOKUP_OFFSET
696 test_expect_success
'git fsck (checks commit-graph)' '
697 cd "$TRASH_DIRECTORY/full" &&
699 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
700 "incorrect checksum" &&
701 cp commit-graph-pre-write-test $objdir/info/commit-graph &&
702 test_must_fail git fsck
705 test_expect_success
'setup non-the_repository tests' '
708 test_commit -C repo one &&
709 test_commit -C repo two &&
710 git -C repo config core.commitGraph true &&
711 git -C repo rev-parse two | \
712 git -C repo commit-graph write --stdin-commits
715 test_expect_success
'parse_commit_in_graph works for non-the_repository' '
716 test-tool repository parse_commit_in_graph \
717 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
719 git -C repo log --pretty=format:"%ct " -1 &&
720 git -C repo rev-parse one
722 test_cmp expect actual &&
724 test-tool repository parse_commit_in_graph \
725 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
726 git -C repo log --pretty="%ct" -1 one >expect &&
727 test_cmp expect actual
730 test_expect_success
'get_commit_tree_in_graph works for non-the_repository' '
731 test-tool repository get_commit_tree_in_graph \
732 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
733 git -C repo rev-parse two^{tree} >expect &&
734 test_cmp expect actual &&
736 test-tool repository get_commit_tree_in_graph \
737 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
738 git -C repo rev-parse one^{tree} >expect &&
739 test_cmp expect actual
742 test_expect_success
'corrupt commit-graph write (broken parent)' '
747 empty="$(git mktree </dev/null)" &&
748 cat >broken <<-EOF &&
751 author whatever <whatever@example.com> 1234 -0000
752 committer whatever <whatever@example.com> 1234 -0000
756 broken="$(git hash-object -w -t commit --literally broken)" &&
757 git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
758 test_must_fail git commit-graph write --stdin-commits \
760 test_i18ngrep "unable to parse commit" test_err
764 test_expect_success
'corrupt commit-graph write (missing tree)' '
769 tree="$(git mktree </dev/null)" &&
770 cat >broken <<-EOF &&
772 author whatever <whatever@example.com> 1234 -0000
773 committer whatever <whatever@example.com> 1234 -0000
777 broken="$(git hash-object -w -t commit --literally broken)" &&
778 git commit-tree -p "$broken" -m "good" "$tree" >good &&
779 test_must_fail git commit-graph write --stdin-commits \
781 test_i18ngrep "unable to parse commit" test_err
785 # We test the overflow-related code with the following repo history:
789 # 1:U - 2:N - 3:U M:N
793 # Here the commits denoted by U have committer date of zero seconds
794 # since Unix epoch, the commits denoted by N have committer date
795 # starting from 1112354055 seconds since Unix epoch (default committer
796 # date for the test suite), and the commits denoted by F have committer
797 # date of (2 ^ 31 - 2) seconds since Unix epoch.
799 # The largest offset observed is 2 ^ 31, just large enough to overflow.
802 test_expect_success
'set up and verify repo with generation data overflow chunk' '
803 objdir=".git/objects" &&
804 UNIX_EPOCH_ZERO="@0 +0000" &&
805 FUTURE_DATE="@2147483646 +0000" &&
806 test_oid_cache <<-EOF &&
810 cd "$TRASH_DIRECTORY" &&
814 test_commit --date "$UNIX_EPOCH_ZERO" 1 &&
816 test_commit --date "$UNIX_EPOCH_ZERO" 3 &&
817 git commit-graph write --reachable &&
818 graph_read_expect 3 generation_data &&
819 test_commit --date "$FUTURE_DATE" 4 &&
821 test_commit --date "$UNIX_EPOCH_ZERO" 6 &&
823 git reset --hard 3 &&
825 test_commit --date "$FUTURE_DATE" 8 &&
828 git reset --hard 3 &&
829 test_merge M left right &&
830 git commit-graph write --reachable &&
831 graph_read_expect 10 "generation_data generation_data_overflow" &&
832 git commit-graph verify
835 graph_git_behavior
'generation data overflow chunk repo' repo left right