send-pack/transport-helper: avoid mentioning a particular branch
[git.git] / t / t5318-commit-graph.sh
bloba79c624875916be83f4cfb86b12156d9571b8d46
1 #!/bin/sh
3 test_description='commit graph'
4 . ./test-lib.sh
6 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
8 test_expect_success 'setup full repo' '
9 mkdir full &&
10 cd "$TRASH_DIRECTORY/full" &&
11 git init &&
12 git config core.commitGraph true &&
13 objdir=".git/objects" &&
14 test_oid_init
17 test_expect_success POSIXPERM 'tweak umask for modebit tests' '
18 umask 022
21 test_expect_success 'verify graph with no graph file' '
22 cd "$TRASH_DIRECTORY/full" &&
23 git commit-graph verify
26 test_expect_success 'write graph with no packs' '
27 cd "$TRASH_DIRECTORY/full" &&
28 git commit-graph write --object-dir $objdir &&
29 test_path_is_missing $objdir/info/commit-graph
32 test_expect_success 'exit with correct error on bad input to --stdin-packs' '
33 cd "$TRASH_DIRECTORY/full" &&
34 echo doesnotexist >in &&
35 test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
36 test_i18ngrep "error adding pack" stderr
39 test_expect_success 'create commits and repack' '
40 cd "$TRASH_DIRECTORY/full" &&
41 for i in $(test_seq 3)
43 test_commit $i &&
44 git branch commits/$i
45 done &&
46 git repack
49 graph_git_two_modes() {
50 git -c core.commitGraph=true $1 >output
51 git -c core.commitGraph=false $1 >expect
52 test_cmp expect output
55 graph_git_behavior() {
56 MSG=$1
57 DIR=$2
58 BRANCH=$3
59 COMPARE=$4
60 test_expect_success "check normal git operations: $MSG" '
61 cd "$TRASH_DIRECTORY/$DIR" &&
62 graph_git_two_modes "log --oneline $BRANCH" &&
63 graph_git_two_modes "log --topo-order $BRANCH" &&
64 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
65 graph_git_two_modes "branch -vv" &&
66 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
70 graph_git_behavior 'no graph' full commits/3 commits/1
72 graph_read_expect() {
73 OPTIONAL=""
74 NUM_CHUNKS=3
75 if test ! -z $2
76 then
77 OPTIONAL=" $2"
78 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
80 cat >expect <<- EOF
81 header: 43475048 1 1 $NUM_CHUNKS 0
82 num_commits: $1
83 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
84 EOF
85 test-tool read-graph >output &&
86 test_cmp expect output
89 test_expect_success 'exit with correct error on bad input to --stdin-commits' '
90 cd "$TRASH_DIRECTORY/full" &&
91 # invalid, non-hex OID
92 echo HEAD >in &&
93 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
94 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
95 # non-existent OID
96 echo $ZERO_OID >in &&
97 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
98 test_i18ngrep "invalid object" stderr &&
99 # valid commit and tree OID
100 git rev-parse HEAD HEAD^{tree} >in &&
101 git commit-graph write --stdin-commits <in &&
102 graph_read_expect 3
105 test_expect_success 'write graph' '
106 cd "$TRASH_DIRECTORY/full" &&
107 git commit-graph write &&
108 test_path_is_file $objdir/info/commit-graph &&
109 graph_read_expect "3"
112 test_expect_success POSIXPERM 'write graph has correct permissions' '
113 test_path_is_file $objdir/info/commit-graph &&
114 echo "-r--r--r--" >expect &&
115 test_modebits $objdir/info/commit-graph >actual &&
116 test_cmp expect actual
119 graph_git_behavior 'graph exists' full commits/3 commits/1
121 test_expect_success 'Add more commits' '
122 cd "$TRASH_DIRECTORY/full" &&
123 git reset --hard commits/1 &&
124 for i in $(test_seq 4 5)
126 test_commit $i &&
127 git branch commits/$i
128 done &&
129 git reset --hard commits/2 &&
130 for i in $(test_seq 6 7)
132 test_commit $i &&
133 git branch commits/$i
134 done &&
135 git reset --hard commits/2 &&
136 git merge commits/4 &&
137 git branch merge/1 &&
138 git reset --hard commits/4 &&
139 git merge commits/6 &&
140 git branch merge/2 &&
141 git reset --hard commits/3 &&
142 git merge commits/5 commits/7 &&
143 git branch merge/3 &&
144 git repack
147 test_expect_success 'commit-graph write progress off for redirected stderr' '
148 cd "$TRASH_DIRECTORY/full" &&
149 git commit-graph write 2>err &&
150 test_line_count = 0 err
153 test_expect_success 'commit-graph write force progress on for stderr' '
154 cd "$TRASH_DIRECTORY/full" &&
155 GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
156 test_file_not_empty err
159 test_expect_success 'commit-graph write with the --no-progress option' '
160 cd "$TRASH_DIRECTORY/full" &&
161 git commit-graph write --no-progress 2>err &&
162 test_line_count = 0 err
165 test_expect_success 'commit-graph verify progress off for redirected stderr' '
166 cd "$TRASH_DIRECTORY/full" &&
167 git commit-graph verify 2>err &&
168 test_line_count = 0 err
171 test_expect_success 'commit-graph verify force progress on for stderr' '
172 cd "$TRASH_DIRECTORY/full" &&
173 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
174 test_file_not_empty err
177 test_expect_success 'commit-graph verify with the --no-progress option' '
178 cd "$TRASH_DIRECTORY/full" &&
179 git commit-graph verify --no-progress 2>err &&
180 test_line_count = 0 err
183 # Current graph structure:
185 # __M3___
186 # / | \
187 # 3 M1 5 M2 7
188 # |/ \|/ \|
189 # 2 4 6
190 # |___/____/
193 test_expect_success 'write graph with merges' '
194 cd "$TRASH_DIRECTORY/full" &&
195 git commit-graph write &&
196 test_path_is_file $objdir/info/commit-graph &&
197 graph_read_expect "10" "extra_edges"
200 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
201 graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
202 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
204 test_expect_success 'Add one more commit' '
205 cd "$TRASH_DIRECTORY/full" &&
206 test_commit 8 &&
207 git branch commits/8 &&
208 ls $objdir/pack | grep idx >existing-idx &&
209 git repack &&
210 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
213 # Current graph structure:
217 # __M3___
218 # / | \
219 # 3 M1 5 M2 7
220 # |/ \|/ \|
221 # 2 4 6
222 # |___/____/
225 graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
226 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
228 test_expect_success 'write graph with new commit' '
229 cd "$TRASH_DIRECTORY/full" &&
230 git commit-graph write &&
231 test_path_is_file $objdir/info/commit-graph &&
232 graph_read_expect "11" "extra_edges"
235 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
236 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
238 test_expect_success 'write graph with nothing new' '
239 cd "$TRASH_DIRECTORY/full" &&
240 git commit-graph write &&
241 test_path_is_file $objdir/info/commit-graph &&
242 graph_read_expect "11" "extra_edges"
245 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
246 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
248 test_expect_success 'build graph from latest pack with closure' '
249 cd "$TRASH_DIRECTORY/full" &&
250 cat new-idx | git commit-graph write --stdin-packs &&
251 test_path_is_file $objdir/info/commit-graph &&
252 graph_read_expect "9" "extra_edges"
255 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
256 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
258 test_expect_success 'build graph from commits with closure' '
259 cd "$TRASH_DIRECTORY/full" &&
260 git tag -a -m "merge" tag/merge merge/2 &&
261 git rev-parse tag/merge >commits-in &&
262 git rev-parse merge/1 >>commits-in &&
263 cat commits-in | git commit-graph write --stdin-commits &&
264 test_path_is_file $objdir/info/commit-graph &&
265 graph_read_expect "6"
268 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
269 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
271 test_expect_success 'build graph from commits with append' '
272 cd "$TRASH_DIRECTORY/full" &&
273 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
274 test_path_is_file $objdir/info/commit-graph &&
275 graph_read_expect "10" "extra_edges"
278 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
279 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
281 test_expect_success 'build graph using --reachable' '
282 cd "$TRASH_DIRECTORY/full" &&
283 git commit-graph write --reachable &&
284 test_path_is_file $objdir/info/commit-graph &&
285 graph_read_expect "11" "extra_edges"
288 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
289 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
291 test_expect_success 'setup bare repo' '
292 cd "$TRASH_DIRECTORY" &&
293 git clone --bare --no-local full bare &&
294 cd bare &&
295 git config core.commitGraph true &&
296 baredir="./objects"
299 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
300 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
302 test_expect_success 'write graph in bare repo' '
303 cd "$TRASH_DIRECTORY/bare" &&
304 git commit-graph write &&
305 test_path_is_file $baredir/info/commit-graph &&
306 graph_read_expect "11" "extra_edges"
309 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
310 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
312 test_expect_success 'perform fast-forward merge in full repo' '
313 cd "$TRASH_DIRECTORY/full" &&
314 git checkout -b merge-5-to-8 commits/5 &&
315 git merge commits/8 &&
316 git show-ref -s merge-5-to-8 >output &&
317 git show-ref -s commits/8 >expect &&
318 test_cmp expect output
321 test_expect_success 'check that gc computes commit-graph' '
322 cd "$TRASH_DIRECTORY/full" &&
323 git commit --allow-empty -m "blank" &&
324 git commit-graph write --reachable &&
325 cp $objdir/info/commit-graph commit-graph-before-gc &&
326 git reset --hard HEAD~1 &&
327 git config gc.writeCommitGraph true &&
328 git gc &&
329 cp $objdir/info/commit-graph commit-graph-after-gc &&
330 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
331 git commit-graph write --reachable &&
332 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
335 test_expect_success 'replace-objects invalidates commit-graph' '
336 cd "$TRASH_DIRECTORY" &&
337 test_when_finished rm -rf replace &&
338 git clone full replace &&
340 cd replace &&
341 git commit-graph write --reachable &&
342 test_path_is_file .git/objects/info/commit-graph &&
343 git replace HEAD~1 HEAD~2 &&
344 git -c core.commitGraph=false log >expect &&
345 git -c core.commitGraph=true log >actual &&
346 test_cmp expect actual &&
347 git commit-graph write --reachable &&
348 git -c core.commitGraph=false --no-replace-objects log >expect &&
349 git -c core.commitGraph=true --no-replace-objects log >actual &&
350 test_cmp expect actual &&
351 rm -rf .git/objects/info/commit-graph &&
352 git commit-graph write --reachable &&
353 test_path_is_file .git/objects/info/commit-graph
357 test_expect_success 'commit grafts invalidate commit-graph' '
358 cd "$TRASH_DIRECTORY" &&
359 test_when_finished rm -rf graft &&
360 git clone full graft &&
362 cd graft &&
363 git commit-graph write --reachable &&
364 test_path_is_file .git/objects/info/commit-graph &&
365 H1=$(git rev-parse --verify HEAD~1) &&
366 H3=$(git rev-parse --verify HEAD~3) &&
367 echo "$H1 $H3" >.git/info/grafts &&
368 git -c core.commitGraph=false log >expect &&
369 git -c core.commitGraph=true log >actual &&
370 test_cmp expect actual &&
371 git commit-graph write --reachable &&
372 git -c core.commitGraph=false --no-replace-objects log >expect &&
373 git -c core.commitGraph=true --no-replace-objects log >actual &&
374 test_cmp expect actual &&
375 rm -rf .git/objects/info/commit-graph &&
376 git commit-graph write --reachable &&
377 test_path_is_missing .git/objects/info/commit-graph
381 test_expect_success 'replace-objects invalidates commit-graph' '
382 cd "$TRASH_DIRECTORY" &&
383 test_when_finished rm -rf shallow &&
384 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
386 cd shallow &&
387 git commit-graph write --reachable &&
388 test_path_is_missing .git/objects/info/commit-graph &&
389 git fetch origin --unshallow &&
390 git commit-graph write --reachable &&
391 test_path_is_file .git/objects/info/commit-graph
395 # the verify tests below expect the commit-graph to contain
396 # exactly the commits reachable from the commits/8 branch.
397 # If the file changes the set of commits in the list, then the
398 # offsets into the binary file will result in different edits
399 # and the tests will likely break.
401 test_expect_success 'git commit-graph verify' '
402 cd "$TRASH_DIRECTORY/full" &&
403 git rev-parse commits/8 | git commit-graph write --stdin-commits &&
404 git commit-graph verify >output
407 NUM_COMMITS=9
408 NUM_OCTOPUS_EDGES=2
409 HASH_LEN="$(test_oid rawsz)"
410 GRAPH_BYTE_VERSION=4
411 GRAPH_BYTE_HASH=5
412 GRAPH_BYTE_CHUNK_COUNT=6
413 GRAPH_CHUNK_LOOKUP_OFFSET=8
414 GRAPH_CHUNK_LOOKUP_WIDTH=12
415 GRAPH_CHUNK_LOOKUP_ROWS=5
416 GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
417 GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
418 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
419 GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
420 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
421 GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
422 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
423 GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
424 GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
425 GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
426 GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
427 GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
428 GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
429 GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
430 GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
431 GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
432 GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
433 GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
434 GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
435 GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
436 GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
437 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
438 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
439 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
441 corrupt_graph_setup() {
442 cd "$TRASH_DIRECTORY/full" &&
443 test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
444 cp $objdir/info/commit-graph commit-graph-backup &&
445 chmod u+w $objdir/info/commit-graph
448 corrupt_graph_verify() {
449 grepstr=$1
450 test_must_fail git commit-graph verify 2>test_err &&
451 grep -v "^+" test_err >err &&
452 test_i18ngrep "$grepstr" err &&
453 if test "$2" != "no-copy"
454 then
455 cp $objdir/info/commit-graph commit-graph-pre-write-test
456 fi &&
457 git status --short &&
458 GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
459 chmod u+w $objdir/info/commit-graph &&
460 git commit-graph verify
463 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
464 # Manipulates the commit-graph file at the position
465 # by inserting the data, optionally zeroing the file
466 # starting at <zero_pos>, then runs 'git commit-graph verify'
467 # and places the output in the file 'err'. Test 'err' for
468 # the given string.
469 corrupt_graph_and_verify() {
470 pos=$1
471 data="${2:-\0}"
472 grepstr=$3
473 corrupt_graph_setup &&
474 orig_size=$(wc -c < $objdir/info/commit-graph) &&
475 zero_pos=${4:-${orig_size}} &&
476 printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
477 dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
478 generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
479 corrupt_graph_verify "$grepstr"
483 test_expect_success POSIXPERM,SANITY 'detect permission problem' '
484 corrupt_graph_setup &&
485 chmod 000 $objdir/info/commit-graph &&
486 corrupt_graph_verify "Could not open" "no-copy"
489 test_expect_success 'detect too small' '
490 corrupt_graph_setup &&
491 echo "a small graph" >$objdir/info/commit-graph &&
492 corrupt_graph_verify "too small"
495 test_expect_success 'detect bad signature' '
496 corrupt_graph_and_verify 0 "\0" \
497 "graph signature"
500 test_expect_success 'detect bad version' '
501 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
502 "graph version"
505 test_expect_success 'detect bad hash version' '
506 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
507 "hash version"
510 test_expect_success 'detect low chunk count' '
511 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
512 "missing the .* chunk"
515 test_expect_success 'detect missing OID fanout chunk' '
516 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
517 "missing the OID Fanout chunk"
520 test_expect_success 'detect missing OID lookup chunk' '
521 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
522 "missing the OID Lookup chunk"
525 test_expect_success 'detect missing commit data chunk' '
526 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
527 "missing the Commit Data chunk"
530 test_expect_success 'detect incorrect fanout' '
531 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
532 "fanout value"
535 test_expect_success 'detect incorrect fanout final value' '
536 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
537 "fanout value"
540 test_expect_success 'detect incorrect OID order' '
541 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
542 "incorrect OID order"
545 test_expect_success 'detect OID not in object database' '
546 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
547 "from object database"
550 test_expect_success 'detect incorrect tree OID' '
551 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
552 "root tree OID for commit"
555 test_expect_success 'detect incorrect parent int-id' '
556 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
557 "invalid parent"
560 test_expect_success 'detect extra parent int-id' '
561 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
562 "is too long"
565 test_expect_success 'detect wrong parent' '
566 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
567 "commit-graph parent for"
570 test_expect_success 'detect incorrect generation number' '
571 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
572 "generation for commit"
575 test_expect_success 'detect incorrect generation number' '
576 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
577 "non-zero generation number"
580 test_expect_success 'detect incorrect commit date' '
581 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
582 "commit date"
585 test_expect_success 'detect incorrect parent for octopus merge' '
586 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
587 "invalid parent"
590 test_expect_success 'detect invalid checksum hash' '
591 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
592 "incorrect checksum"
595 test_expect_success 'detect incorrect chunk count' '
596 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
597 "chunk lookup table entry missing" $GRAPH_CHUNK_LOOKUP_OFFSET
600 test_expect_success 'git fsck (checks commit-graph)' '
601 cd "$TRASH_DIRECTORY/full" &&
602 git fsck &&
603 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
604 "incorrect checksum" &&
605 cp commit-graph-pre-write-test $objdir/info/commit-graph &&
606 test_must_fail git fsck
609 test_expect_success 'setup non-the_repository tests' '
610 rm -rf repo &&
611 git init repo &&
612 test_commit -C repo one &&
613 test_commit -C repo two &&
614 git -C repo config core.commitGraph true &&
615 git -C repo rev-parse two | \
616 git -C repo commit-graph write --stdin-commits
619 test_expect_success 'parse_commit_in_graph works for non-the_repository' '
620 test-tool repository parse_commit_in_graph \
621 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
623 git -C repo log --pretty=format:"%ct " -1 &&
624 git -C repo rev-parse one
625 } >expect &&
626 test_cmp expect actual &&
628 test-tool repository parse_commit_in_graph \
629 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
630 git -C repo log --pretty="%ct" -1 one >expect &&
631 test_cmp expect actual
634 test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
635 test-tool repository get_commit_tree_in_graph \
636 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
637 git -C repo rev-parse two^{tree} >expect &&
638 test_cmp expect actual &&
640 test-tool repository get_commit_tree_in_graph \
641 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
642 git -C repo rev-parse one^{tree} >expect &&
643 test_cmp expect actual
646 test_expect_success 'corrupt commit-graph write (broken parent)' '
647 rm -rf repo &&
648 git init repo &&
650 cd repo &&
651 empty="$(git mktree </dev/null)" &&
652 cat >broken <<-EOF &&
653 tree $empty
654 parent $ZERO_OID
655 author whatever <whatever@example.com> 1234 -0000
656 committer whatever <whatever@example.com> 1234 -0000
658 broken commit
660 broken="$(git hash-object -w -t commit --literally broken)" &&
661 git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
662 test_must_fail git commit-graph write --stdin-commits \
663 <good 2>test_err &&
664 test_i18ngrep "unable to parse commit" test_err
668 test_expect_success 'corrupt commit-graph write (missing tree)' '
669 rm -rf repo &&
670 git init repo &&
672 cd repo &&
673 tree="$(git mktree </dev/null)" &&
674 cat >broken <<-EOF &&
675 parent $ZERO_OID
676 author whatever <whatever@example.com> 1234 -0000
677 committer whatever <whatever@example.com> 1234 -0000
679 broken commit
681 broken="$(git hash-object -w -t commit --literally broken)" &&
682 git commit-tree -p "$broken" -m "good" "$tree" >good &&
683 test_must_fail git commit-graph write --stdin-commits \
684 <good 2>test_err &&
685 test_i18ngrep "unable to parse commit" test_err
689 test_done