3 test_description
='commit graph'
6 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS
=0
8 test_expect_success
'setup full repo' '
10 cd "$TRASH_DIRECTORY/full" &&
12 git config core.commitGraph true &&
13 objdir=".git/objects" &&
21 test_expect_success POSIXPERM
'tweak umask for modebit tests' '
25 test_expect_success
'verify graph with no graph file' '
26 cd "$TRASH_DIRECTORY/full" &&
27 git commit-graph verify
30 test_expect_success
'write graph with no packs' '
31 cd "$TRASH_DIRECTORY/full" &&
32 git commit-graph write --object-dir $objdir &&
33 test_path_is_missing $objdir/info/commit-graph
36 test_expect_success
'exit with correct error on bad input to --stdin-packs' '
37 cd "$TRASH_DIRECTORY/full" &&
38 echo doesnotexist >in &&
39 test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
40 test_i18ngrep "error adding pack" stderr
43 test_expect_success
'create commits and repack' '
44 cd "$TRASH_DIRECTORY/full" &&
45 for i in $(test_seq 3)
53 graph_git_two_modes
() {
54 git
-c core.commitGraph
=true
$1 >output
55 git
-c core.commitGraph
=false
$1 >expect
56 test_cmp expect output
59 graph_git_behavior
() {
64 test_expect_success
"check normal git operations: $MSG" '
65 cd "$TRASH_DIRECTORY/$DIR" &&
66 graph_git_two_modes "log --oneline $BRANCH" &&
67 graph_git_two_modes "log --topo-order $BRANCH" &&
68 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
69 graph_git_two_modes "branch -vv" &&
70 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
74 graph_git_behavior
'no graph' full commits
/3 commits
/1
82 NUM_CHUNKS
=$
((3 + $
(echo "$2" |
wc -w)))
85 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
87 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
89 test-tool read-graph
>output
&&
90 test_cmp expect output
93 test_expect_success
'exit with correct error on bad input to --stdin-commits' '
94 cd "$TRASH_DIRECTORY/full" &&
95 # invalid, non-hex OID
97 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
98 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
100 echo $ZERO_OID >in &&
101 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
102 test_i18ngrep "invalid object" stderr &&
103 # valid commit and tree OID
104 git rev-parse HEAD HEAD^{tree} >in &&
105 git commit-graph write --stdin-commits <in &&
106 graph_read_expect 3 generation_data
109 test_expect_success
'write graph' '
110 cd "$TRASH_DIRECTORY/full" &&
111 git commit-graph write &&
112 test_path_is_file $objdir/info/commit-graph &&
113 graph_read_expect "3" generation_data
116 test_expect_success POSIXPERM
'write graph has correct permissions' '
117 test_path_is_file $objdir/info/commit-graph &&
118 echo "-r--r--r--" >expect &&
119 test_modebits $objdir/info/commit-graph >actual &&
120 test_cmp expect actual
123 graph_git_behavior
'graph exists' full commits
/3 commits
/1
125 test_expect_success
'Add more commits' '
126 cd "$TRASH_DIRECTORY/full" &&
127 git reset --hard commits/1 &&
128 for i in $(test_seq 4 5)
131 git branch commits/$i
133 git reset --hard commits/2 &&
134 for i in $(test_seq 6 7)
137 git branch commits/$i
139 git reset --hard commits/2 &&
140 git merge commits/4 &&
141 git branch merge/1 &&
142 git reset --hard commits/4 &&
143 git merge commits/6 &&
144 git branch merge/2 &&
145 git reset --hard commits/3 &&
146 git merge commits/5 commits/7 &&
147 git branch merge/3 &&
151 test_expect_success
'commit-graph write progress off for redirected stderr' '
152 cd "$TRASH_DIRECTORY/full" &&
153 git commit-graph write 2>err &&
154 test_must_be_empty err
157 test_expect_success
'commit-graph write force progress on for stderr' '
158 cd "$TRASH_DIRECTORY/full" &&
159 GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
160 test_file_not_empty err
163 test_expect_success
'commit-graph write with the --no-progress option' '
164 cd "$TRASH_DIRECTORY/full" &&
165 git commit-graph write --no-progress 2>err &&
166 test_must_be_empty err
169 test_expect_success
'commit-graph write --stdin-commits progress off for redirected stderr' '
170 cd "$TRASH_DIRECTORY/full" &&
171 git rev-parse commits/5 >in &&
172 git commit-graph write --stdin-commits <in 2>err &&
173 test_must_be_empty err
176 test_expect_success
'commit-graph write --stdin-commits force progress on for stderr' '
177 cd "$TRASH_DIRECTORY/full" &&
178 git rev-parse commits/5 >in &&
179 GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err &&
180 test_i18ngrep "Collecting commits from input" err
183 test_expect_success
'commit-graph write --stdin-commits with the --no-progress option' '
184 cd "$TRASH_DIRECTORY/full" &&
185 git rev-parse commits/5 >in &&
186 git commit-graph write --stdin-commits --no-progress <in 2>err &&
187 test_must_be_empty err
190 test_expect_success
'commit-graph verify progress off for redirected stderr' '
191 cd "$TRASH_DIRECTORY/full" &&
192 git commit-graph verify 2>err &&
193 test_must_be_empty err
196 test_expect_success
'commit-graph verify force progress on for stderr' '
197 cd "$TRASH_DIRECTORY/full" &&
198 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
199 test_file_not_empty err
202 test_expect_success
'commit-graph verify with the --no-progress option' '
203 cd "$TRASH_DIRECTORY/full" &&
204 git commit-graph verify --no-progress 2>err &&
205 test_must_be_empty err
208 # Current graph structure:
218 test_expect_success
'write graph with merges' '
219 cd "$TRASH_DIRECTORY/full" &&
220 git commit-graph write &&
221 test_path_is_file $objdir/info/commit-graph &&
222 graph_read_expect "10" "generation_data extra_edges"
225 graph_git_behavior
'merge 1 vs 2' full merge
/1 merge
/2
226 graph_git_behavior
'merge 1 vs 3' full merge
/1 merge
/3
227 graph_git_behavior
'merge 2 vs 3' full merge
/2 merge
/3
229 test_expect_success
'Add one more commit' '
230 cd "$TRASH_DIRECTORY/full" &&
232 git branch commits/8 &&
233 ls $objdir/pack | grep idx >existing-idx &&
235 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
238 # Current graph structure:
250 graph_git_behavior
'mixed mode, commit 8 vs merge 1' full commits
/8 merge
/1
251 graph_git_behavior
'mixed mode, commit 8 vs merge 2' full commits
/8 merge
/2
253 test_expect_success
'write graph with new commit' '
254 cd "$TRASH_DIRECTORY/full" &&
255 git commit-graph write &&
256 test_path_is_file $objdir/info/commit-graph &&
257 graph_read_expect "11" "generation_data extra_edges"
260 graph_git_behavior
'full graph, commit 8 vs merge 1' full commits
/8 merge
/1
261 graph_git_behavior
'full graph, commit 8 vs merge 2' full commits
/8 merge
/2
263 test_expect_success
'write graph with nothing new' '
264 cd "$TRASH_DIRECTORY/full" &&
265 git commit-graph write &&
266 test_path_is_file $objdir/info/commit-graph &&
267 graph_read_expect "11" "generation_data extra_edges"
270 graph_git_behavior
'cleared graph, commit 8 vs merge 1' full commits
/8 merge
/1
271 graph_git_behavior
'cleared graph, commit 8 vs merge 2' full commits
/8 merge
/2
273 test_expect_success
'build graph from latest pack with closure' '
274 cd "$TRASH_DIRECTORY/full" &&
275 cat new-idx | git commit-graph write --stdin-packs &&
276 test_path_is_file $objdir/info/commit-graph &&
277 graph_read_expect "9" "generation_data extra_edges"
280 graph_git_behavior
'graph from pack, commit 8 vs merge 1' full commits
/8 merge
/1
281 graph_git_behavior
'graph from pack, commit 8 vs merge 2' full commits
/8 merge
/2
283 test_expect_success
'build graph from commits with closure' '
284 cd "$TRASH_DIRECTORY/full" &&
285 git tag -a -m "merge" tag/merge merge/2 &&
286 git rev-parse tag/merge >commits-in &&
287 git rev-parse merge/1 >>commits-in &&
288 cat commits-in | git commit-graph write --stdin-commits &&
289 test_path_is_file $objdir/info/commit-graph &&
290 graph_read_expect "6" "generation_data"
293 graph_git_behavior
'graph from commits, commit 8 vs merge 1' full commits
/8 merge
/1
294 graph_git_behavior
'graph from commits, commit 8 vs merge 2' full commits
/8 merge
/2
296 test_expect_success
'build graph from commits with append' '
297 cd "$TRASH_DIRECTORY/full" &&
298 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
299 test_path_is_file $objdir/info/commit-graph &&
300 graph_read_expect "10" "generation_data extra_edges"
303 graph_git_behavior
'append graph, commit 8 vs merge 1' full commits
/8 merge
/1
304 graph_git_behavior
'append graph, commit 8 vs merge 2' full commits
/8 merge
/2
306 test_expect_success
'build graph using --reachable' '
307 cd "$TRASH_DIRECTORY/full" &&
308 git commit-graph write --reachable &&
309 test_path_is_file $objdir/info/commit-graph &&
310 graph_read_expect "11" "generation_data extra_edges"
313 graph_git_behavior
'append graph, commit 8 vs merge 1' full commits
/8 merge
/1
314 graph_git_behavior
'append graph, commit 8 vs merge 2' full commits
/8 merge
/2
316 test_expect_success
'setup bare repo' '
317 cd "$TRASH_DIRECTORY" &&
318 git clone --bare --no-local full bare &&
320 git config core.commitGraph true &&
324 graph_git_behavior
'bare repo, commit 8 vs merge 1' bare commits
/8 merge
/1
325 graph_git_behavior
'bare repo, commit 8 vs merge 2' bare commits
/8 merge
/2
327 test_expect_success
'write graph in bare repo' '
328 cd "$TRASH_DIRECTORY/bare" &&
329 git commit-graph write &&
330 test_path_is_file $baredir/info/commit-graph &&
331 graph_read_expect "11" "generation_data extra_edges"
334 graph_git_behavior
'bare repo with graph, commit 8 vs merge 1' bare commits
/8 merge
/1
335 graph_git_behavior
'bare repo with graph, commit 8 vs merge 2' bare commits
/8 merge
/2
337 test_expect_success
'perform fast-forward merge in full repo' '
338 cd "$TRASH_DIRECTORY/full" &&
339 git checkout -b merge-5-to-8 commits/5 &&
340 git merge commits/8 &&
341 git show-ref -s merge-5-to-8 >output &&
342 git show-ref -s commits/8 >expect &&
343 test_cmp expect output
346 test_expect_success
'check that gc computes commit-graph' '
347 cd "$TRASH_DIRECTORY/full" &&
348 git commit --allow-empty -m "blank" &&
349 git commit-graph write --reachable &&
350 cp $objdir/info/commit-graph commit-graph-before-gc &&
351 git reset --hard HEAD~1 &&
352 git config gc.writeCommitGraph true &&
354 cp $objdir/info/commit-graph commit-graph-after-gc &&
355 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
356 git commit-graph write --reachable &&
357 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
360 test_expect_success
'replace-objects invalidates commit-graph' '
361 cd "$TRASH_DIRECTORY" &&
362 test_when_finished rm -rf replace &&
363 git clone full replace &&
366 git commit-graph write --reachable &&
367 test_path_is_file .git/objects/info/commit-graph &&
368 git replace HEAD~1 HEAD~2 &&
369 git -c core.commitGraph=false log >expect &&
370 git -c core.commitGraph=true log >actual &&
371 test_cmp expect actual &&
372 git commit-graph write --reachable &&
373 git -c core.commitGraph=false --no-replace-objects log >expect &&
374 git -c core.commitGraph=true --no-replace-objects log >actual &&
375 test_cmp expect actual &&
376 rm -rf .git/objects/info/commit-graph &&
377 git commit-graph write --reachable &&
378 test_path_is_file .git/objects/info/commit-graph
382 test_expect_success
'commit grafts invalidate commit-graph' '
383 cd "$TRASH_DIRECTORY" &&
384 test_when_finished rm -rf graft &&
385 git clone full graft &&
388 git commit-graph write --reachable &&
389 test_path_is_file .git/objects/info/commit-graph &&
390 H1=$(git rev-parse --verify HEAD~1) &&
391 H3=$(git rev-parse --verify HEAD~3) &&
392 echo "$H1 $H3" >.git/info/grafts &&
393 git -c core.commitGraph=false log >expect &&
394 git -c core.commitGraph=true log >actual &&
395 test_cmp expect actual &&
396 git commit-graph write --reachable &&
397 git -c core.commitGraph=false --no-replace-objects log >expect &&
398 git -c core.commitGraph=true --no-replace-objects log >actual &&
399 test_cmp expect actual &&
400 rm -rf .git/objects/info/commit-graph &&
401 git commit-graph write --reachable &&
402 test_path_is_missing .git/objects/info/commit-graph
406 test_expect_success
'replace-objects invalidates commit-graph' '
407 cd "$TRASH_DIRECTORY" &&
408 test_when_finished rm -rf shallow &&
409 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
412 git commit-graph write --reachable &&
413 test_path_is_missing .git/objects/info/commit-graph &&
414 git fetch origin --unshallow &&
415 git commit-graph write --reachable &&
416 test_path_is_file .git/objects/info/commit-graph
420 test_expect_success
'warn on improper hash version' '
421 git init --object-format=sha1 sha1 &&
425 git commit-graph write --reachable &&
426 mv .git/objects/info/commit-graph ../cg-sha1
428 git init --object-format=sha256 sha256 &&
432 git commit-graph write --reachable &&
433 mv .git/objects/info/commit-graph ../cg-sha256
437 mv ../cg-sha256 .git/objects/info/commit-graph &&
439 test_i18ngrep "commit-graph hash version 2 does not match version 1" err
443 mv ../cg-sha1 .git/objects/info/commit-graph &&
445 test_i18ngrep "commit-graph hash version 1 does not match version 2" err
449 # the verify tests below expect the commit-graph to contain
450 # exactly the commits reachable from the commits/8 branch.
451 # If the file changes the set of commits in the list, then the
452 # offsets into the binary file will result in different edits
453 # and the tests will likely break.
455 test_expect_success
'git commit-graph verify' '
456 cd "$TRASH_DIRECTORY/full" &&
457 git rev-parse commits/8 | GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --stdin-commits &&
458 git commit-graph verify >output &&
459 graph_read_expect 9 extra_edges
464 HASH_LEN
="$(test_oid rawsz)"
467 GRAPH_BYTE_CHUNK_COUNT
=6
468 GRAPH_CHUNK_LOOKUP_OFFSET
=8
469 GRAPH_CHUNK_LOOKUP_WIDTH
=12
470 GRAPH_CHUNK_LOOKUP_ROWS
=5
471 GRAPH_BYTE_OID_FANOUT_ID
=$GRAPH_CHUNK_LOOKUP_OFFSET
472 GRAPH_BYTE_OID_LOOKUP_ID
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
473 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
474 GRAPH_BYTE_COMMIT_DATA_ID
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
475 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
476 GRAPH_FANOUT_OFFSET
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
477 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
478 GRAPH_BYTE_FANOUT1
=$
(($GRAPH_FANOUT_OFFSET + 4 * 4))
479 GRAPH_BYTE_FANOUT2
=$
(($GRAPH_FANOUT_OFFSET + 4 * 255))
480 GRAPH_OID_LOOKUP_OFFSET
=$
(($GRAPH_FANOUT_OFFSET + 4 * 256))
481 GRAPH_BYTE_OID_LOOKUP_ORDER
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
482 GRAPH_BYTE_OID_LOOKUP_MISSING
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
483 GRAPH_COMMIT_DATA_OFFSET
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
484 GRAPH_BYTE_COMMIT_TREE
=$GRAPH_COMMIT_DATA_OFFSET
485 GRAPH_BYTE_COMMIT_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
486 GRAPH_BYTE_COMMIT_EXTRA_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
487 GRAPH_BYTE_COMMIT_WRONG_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
488 GRAPH_BYTE_COMMIT_GENERATION
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
489 GRAPH_BYTE_COMMIT_DATE
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
490 GRAPH_COMMIT_DATA_WIDTH
=$
(($HASH_LEN + 16))
491 GRAPH_OCTOPUS_DATA_OFFSET
=$
(($GRAPH_COMMIT_DATA_OFFSET + \
492 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
493 GRAPH_BYTE_OCTOPUS
=$
(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
494 GRAPH_BYTE_FOOTER
=$
(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
496 corrupt_graph_setup
() {
497 cd "$TRASH_DIRECTORY/full" &&
498 test_when_finished
mv commit-graph-backup
$objdir/info
/commit-graph
&&
499 cp $objdir/info
/commit-graph commit-graph-backup
&&
500 chmod u
+w
$objdir/info
/commit-graph
503 corrupt_graph_verify
() {
505 test_must_fail git commit-graph verify
2>test_err
&&
506 grep -v "^+" test_err
>err
&&
507 test_i18ngrep
"$grepstr" err
&&
508 if test "$2" != "no-copy"
510 cp $objdir/info
/commit-graph commit-graph-pre-write-test
512 git status
--short &&
513 GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE
=true git commit-graph
write &&
514 chmod u
+w
$objdir/info
/commit-graph
&&
515 git commit-graph verify
518 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
519 # Manipulates the commit-graph file at the position
520 # by inserting the data, optionally zeroing the file
521 # starting at <zero_pos>, then runs 'git commit-graph verify'
522 # and places the output in the file 'err'. Test 'err' for
524 corrupt_graph_and_verify
() {
528 corrupt_graph_setup
&&
529 orig_size
=$
(wc -c < $objdir/info
/commit-graph
) &&
530 zero_pos
=${4:-${orig_size}} &&
531 printf "$data" |
dd of
="$objdir/info/commit-graph" bs
=1 seek
="$pos" conv
=notrunc
&&
532 dd of
="$objdir/info/commit-graph" bs
=1 seek
="$zero_pos" if=/dev
/null
&&
533 generate_zero_bytes $
(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
534 corrupt_graph_verify
"$grepstr"
538 test_expect_success POSIXPERM
,SANITY
'detect permission problem' '
539 corrupt_graph_setup &&
540 chmod 000 $objdir/info/commit-graph &&
541 corrupt_graph_verify "Could not open" "no-copy"
544 test_expect_success
'detect too small' '
545 corrupt_graph_setup &&
546 echo "a small graph" >$objdir/info/commit-graph &&
547 corrupt_graph_verify "too small"
550 test_expect_success
'detect bad signature' '
551 corrupt_graph_and_verify 0 "\0" \
555 test_expect_success
'detect bad version' '
556 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
560 test_expect_success
'detect bad hash version' '
561 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
565 test_expect_success
'detect low chunk count' '
566 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\01" \
567 "missing the .* chunk"
570 test_expect_success
'detect missing OID fanout chunk' '
571 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
572 "missing the OID Fanout chunk"
575 test_expect_success
'detect missing OID lookup chunk' '
576 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
577 "missing the OID Lookup chunk"
580 test_expect_success
'detect missing commit data chunk' '
581 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
582 "missing the Commit Data chunk"
585 test_expect_success
'detect incorrect fanout' '
586 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
590 test_expect_success
'detect incorrect fanout final value' '
591 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
595 test_expect_success
'detect incorrect OID order' '
596 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
597 "incorrect OID order"
600 test_expect_success
'detect OID not in object database' '
601 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
602 "from object database"
605 test_expect_success
'detect incorrect tree OID' '
606 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
607 "root tree OID for commit"
610 test_expect_success
'detect incorrect parent int-id' '
611 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
615 test_expect_success
'detect extra parent int-id' '
616 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
620 test_expect_success
'detect wrong parent' '
621 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
622 "commit-graph parent for"
625 test_expect_success
'detect incorrect generation number' '
626 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
627 "generation for commit"
630 test_expect_success
'detect incorrect generation number' '
631 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
632 "non-zero generation number"
635 test_expect_success
'detect incorrect commit date' '
636 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
640 test_expect_success
'detect incorrect parent for octopus merge' '
641 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
645 test_expect_success
'detect invalid checksum hash' '
646 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
650 test_expect_success
'detect incorrect chunk count' '
651 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
652 "commit-graph file is too small to hold [0-9]* chunks" \
653 $GRAPH_CHUNK_LOOKUP_OFFSET
656 test_expect_success
'git fsck (checks commit-graph)' '
657 cd "$TRASH_DIRECTORY/full" &&
659 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
660 "incorrect checksum" &&
661 cp commit-graph-pre-write-test $objdir/info/commit-graph &&
662 test_must_fail git fsck
665 test_expect_success
'setup non-the_repository tests' '
668 test_commit -C repo one &&
669 test_commit -C repo two &&
670 git -C repo config core.commitGraph true &&
671 git -C repo rev-parse two | \
672 git -C repo commit-graph write --stdin-commits
675 test_expect_success
'parse_commit_in_graph works for non-the_repository' '
676 test-tool repository parse_commit_in_graph \
677 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
679 git -C repo log --pretty=format:"%ct " -1 &&
680 git -C repo rev-parse one
682 test_cmp expect actual &&
684 test-tool repository parse_commit_in_graph \
685 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
686 git -C repo log --pretty="%ct" -1 one >expect &&
687 test_cmp expect actual
690 test_expect_success
'get_commit_tree_in_graph works for non-the_repository' '
691 test-tool repository get_commit_tree_in_graph \
692 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
693 git -C repo rev-parse two^{tree} >expect &&
694 test_cmp expect actual &&
696 test-tool repository get_commit_tree_in_graph \
697 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
698 git -C repo rev-parse one^{tree} >expect &&
699 test_cmp expect actual
702 test_expect_success
'corrupt commit-graph write (broken parent)' '
707 empty="$(git mktree </dev/null)" &&
708 cat >broken <<-EOF &&
711 author whatever <whatever@example.com> 1234 -0000
712 committer whatever <whatever@example.com> 1234 -0000
716 broken="$(git hash-object -w -t commit --literally broken)" &&
717 git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
718 test_must_fail git commit-graph write --stdin-commits \
720 test_i18ngrep "unable to parse commit" test_err
724 test_expect_success
'corrupt commit-graph write (missing tree)' '
729 tree="$(git mktree </dev/null)" &&
730 cat >broken <<-EOF &&
732 author whatever <whatever@example.com> 1234 -0000
733 committer whatever <whatever@example.com> 1234 -0000
737 broken="$(git hash-object -w -t commit --literally broken)" &&
738 git commit-tree -p "$broken" -m "good" "$tree" >good &&
739 test_must_fail git commit-graph write --stdin-commits \
741 test_i18ngrep "unable to parse commit" test_err
745 # We test the overflow-related code with the following repo history:
749 # 1:U - 2:N - 3:U M:N
753 # Here the commits denoted by U have committer date of zero seconds
754 # since Unix epoch, the commits denoted by N have committer date
755 # starting from 1112354055 seconds since Unix epoch (default committer
756 # date for the test suite), and the commits denoted by F have committer
757 # date of (2 ^ 31 - 2) seconds since Unix epoch.
759 # The largest offset observed is 2 ^ 31, just large enough to overflow.
762 test_expect_success
'set up and verify repo with generation data overflow chunk' '
763 objdir=".git/objects" &&
764 UNIX_EPOCH_ZERO="@0 +0000" &&
765 FUTURE_DATE="@2147483646 +0000" &&
766 test_oid_cache <<-EOF &&
770 cd "$TRASH_DIRECTORY" &&
774 test_commit --date "$UNIX_EPOCH_ZERO" 1 &&
776 test_commit --date "$UNIX_EPOCH_ZERO" 3 &&
777 git commit-graph write --reachable &&
778 graph_read_expect 3 generation_data &&
779 test_commit --date "$FUTURE_DATE" 4 &&
781 test_commit --date "$UNIX_EPOCH_ZERO" 6 &&
783 git reset --hard 3 &&
785 test_commit --date "$FUTURE_DATE" 8 &&
788 git reset --hard 3 &&
789 test_merge M left right &&
790 git commit-graph write --reachable &&
791 graph_read_expect 10 "generation_data generation_data_overflow" &&
792 git commit-graph verify
795 graph_git_behavior
'generation data overflow chunk repo' repo left right