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 &&
16 test_expect_success POSIXPERM 'tweak umask for modebit tests' '
20 test_expect_success 'verify graph with no graph file' '
21 cd "$TRASH_DIRECTORY/full" &&
22 git commit-graph verify
25 test_expect_success 'write graph with no packs' '
26 cd "$TRASH_DIRECTORY/full" &&
27 git commit-graph write --object-dir $objdir &&
28 test_path_is_missing $objdir/info/commit-graph
31 test_expect_success 'exit with correct error on bad input to --stdin-packs' '
32 cd "$TRASH_DIRECTORY/full" &&
33 echo doesnotexist >in &&
34 test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
35 test_i18ngrep "error adding pack" stderr
38 test_expect_success 'create commits and repack' '
39 cd "$TRASH_DIRECTORY/full" &&
40 for i in $(test_seq 3)
48 graph_git_two_modes() {
49 git -c core.commitGraph=true $1 >output
50 git -c core.commitGraph=false $1 >expect
51 test_cmp expect output
54 graph_git_behavior() {
59 test_expect_success "check normal git operations: $MSG" '
60 cd "$TRASH_DIRECTORY/$DIR" &&
61 graph_git_two_modes "log --oneline $BRANCH" &&
62 graph_git_two_modes "log --topo-order $BRANCH" &&
63 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
64 graph_git_two_modes "branch -vv" &&
65 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
69 graph_git_behavior 'no graph' full commits/3 commits/1
77 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
80 header: 43475048 1 1 $NUM_CHUNKS 0
82 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
84 test-tool read-graph >output &&
85 test_cmp expect output
88 test_expect_success 'exit with correct error on bad input to --stdin-commits' '
89 cd "$TRASH_DIRECTORY/full" &&
90 # invalid, non-hex OID
92 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
93 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
96 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
97 test_i18ngrep "invalid object" stderr &&
98 # valid commit and tree OID
99 git rev-parse HEAD HEAD^{tree} >in &&
100 git commit-graph write --stdin-commits <in &&
104 test_expect_success 'write graph' '
105 cd "$TRASH_DIRECTORY/full" &&
106 git commit-graph write &&
107 test_path_is_file $objdir/info/commit-graph &&
108 graph_read_expect "3"
111 test_expect_success POSIXPERM 'write graph has correct permissions' '
112 test_path_is_file $objdir/info/commit-graph &&
113 echo "-r--r--r--" >expect &&
114 test_modebits $objdir/info/commit-graph >actual &&
115 test_cmp expect actual
118 graph_git_behavior 'graph exists' full commits/3 commits/1
120 test_expect_success 'Add more commits' '
121 cd "$TRASH_DIRECTORY/full" &&
122 git reset --hard commits/1 &&
123 for i in $(test_seq 4 5)
126 git branch commits/$i
128 git reset --hard commits/2 &&
129 for i in $(test_seq 6 7)
132 git branch commits/$i
134 git reset --hard commits/2 &&
135 git merge commits/4 &&
136 git branch merge/1 &&
137 git reset --hard commits/4 &&
138 git merge commits/6 &&
139 git branch merge/2 &&
140 git reset --hard commits/3 &&
141 git merge commits/5 commits/7 &&
142 git branch merge/3 &&
146 test_expect_success 'commit-graph write progress off for redirected stderr' '
147 cd "$TRASH_DIRECTORY/full" &&
148 git commit-graph write 2>err &&
149 test_must_be_empty err
152 test_expect_success 'commit-graph write force progress on for stderr' '
153 cd "$TRASH_DIRECTORY/full" &&
154 GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
155 test_file_not_empty err
158 test_expect_success 'commit-graph write with the --no-progress option' '
159 cd "$TRASH_DIRECTORY/full" &&
160 git commit-graph write --no-progress 2>err &&
161 test_must_be_empty err
164 test_expect_success 'commit-graph write --stdin-commits progress off for redirected stderr' '
165 cd "$TRASH_DIRECTORY/full" &&
166 git rev-parse commits/5 >in &&
167 git commit-graph write --stdin-commits <in 2>err &&
168 test_must_be_empty err
171 test_expect_success 'commit-graph write --stdin-commits force progress on for stderr' '
172 cd "$TRASH_DIRECTORY/full" &&
173 git rev-parse commits/5 >in &&
174 GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err &&
175 test_i18ngrep "Collecting commits from input" err
178 test_expect_success 'commit-graph write --stdin-commits with the --no-progress option' '
179 cd "$TRASH_DIRECTORY/full" &&
180 git rev-parse commits/5 >in &&
181 git commit-graph write --stdin-commits --no-progress <in 2>err &&
182 test_must_be_empty err
185 test_expect_success 'commit-graph verify progress off for redirected stderr' '
186 cd "$TRASH_DIRECTORY/full" &&
187 git commit-graph verify 2>err &&
188 test_must_be_empty err
191 test_expect_success 'commit-graph verify force progress on for stderr' '
192 cd "$TRASH_DIRECTORY/full" &&
193 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
194 test_file_not_empty err
197 test_expect_success 'commit-graph verify with the --no-progress option' '
198 cd "$TRASH_DIRECTORY/full" &&
199 git commit-graph verify --no-progress 2>err &&
200 test_must_be_empty err
203 # Current graph structure:
213 test_expect_success 'write graph with merges' '
214 cd "$TRASH_DIRECTORY/full" &&
215 git commit-graph write &&
216 test_path_is_file $objdir/info/commit-graph &&
217 graph_read_expect "10" "extra_edges"
220 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
221 graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
222 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
224 test_expect_success 'Add one more commit' '
225 cd "$TRASH_DIRECTORY/full" &&
227 git branch commits/8 &&
228 ls $objdir/pack | grep idx >existing-idx &&
230 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
233 # Current graph structure:
245 graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
246 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
248 test_expect_success 'write graph with new commit' '
249 cd "$TRASH_DIRECTORY/full" &&
250 git commit-graph write &&
251 test_path_is_file $objdir/info/commit-graph &&
252 graph_read_expect "11" "extra_edges"
255 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
256 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
258 test_expect_success 'write graph with nothing new' '
259 cd "$TRASH_DIRECTORY/full" &&
260 git commit-graph write &&
261 test_path_is_file $objdir/info/commit-graph &&
262 graph_read_expect "11" "extra_edges"
265 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
266 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
268 test_expect_success 'build graph from latest pack with closure' '
269 cd "$TRASH_DIRECTORY/full" &&
270 cat new-idx | git commit-graph write --stdin-packs &&
271 test_path_is_file $objdir/info/commit-graph &&
272 graph_read_expect "9" "extra_edges"
275 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
276 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
278 test_expect_success 'build graph from commits with closure' '
279 cd "$TRASH_DIRECTORY/full" &&
280 git tag -a -m "merge" tag/merge merge/2 &&
281 git rev-parse tag/merge >commits-in &&
282 git rev-parse merge/1 >>commits-in &&
283 cat commits-in | git commit-graph write --stdin-commits &&
284 test_path_is_file $objdir/info/commit-graph &&
285 graph_read_expect "6"
288 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
289 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
291 test_expect_success 'build graph from commits with append' '
292 cd "$TRASH_DIRECTORY/full" &&
293 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
294 test_path_is_file $objdir/info/commit-graph &&
295 graph_read_expect "10" "extra_edges"
298 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
299 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
301 test_expect_success 'build graph using --reachable' '
302 cd "$TRASH_DIRECTORY/full" &&
303 git commit-graph write --reachable &&
304 test_path_is_file $objdir/info/commit-graph &&
305 graph_read_expect "11" "extra_edges"
308 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
309 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
311 test_expect_success 'setup bare repo' '
312 cd "$TRASH_DIRECTORY" &&
313 git clone --bare --no-local full bare &&
315 git config core.commitGraph true &&
319 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
320 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
322 test_expect_success 'write graph in bare repo' '
323 cd "$TRASH_DIRECTORY/bare" &&
324 git commit-graph write &&
325 test_path_is_file $baredir/info/commit-graph &&
326 graph_read_expect "11" "extra_edges"
329 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
330 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
332 test_expect_success 'perform fast-forward merge in full repo' '
333 cd "$TRASH_DIRECTORY/full" &&
334 git checkout -b merge-5-to-8 commits/5 &&
335 git merge commits/8 &&
336 git show-ref -s merge-5-to-8 >output &&
337 git show-ref -s commits/8 >expect &&
338 test_cmp expect output
341 test_expect_success 'check that gc computes commit-graph' '
342 cd "$TRASH_DIRECTORY/full" &&
343 git commit --allow-empty -m "blank" &&
344 git commit-graph write --reachable &&
345 cp $objdir/info/commit-graph commit-graph-before-gc &&
346 git reset --hard HEAD~1 &&
347 git config gc.writeCommitGraph true &&
349 cp $objdir/info/commit-graph commit-graph-after-gc &&
350 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
351 git commit-graph write --reachable &&
352 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
355 test_expect_success 'replace-objects invalidates commit-graph' '
356 cd "$TRASH_DIRECTORY" &&
357 test_when_finished rm -rf replace &&
358 git clone full replace &&
361 git commit-graph write --reachable &&
362 test_path_is_file .git/objects/info/commit-graph &&
363 git replace HEAD~1 HEAD~2 &&
364 git -c core.commitGraph=false log >expect &&
365 git -c core.commitGraph=true log >actual &&
366 test_cmp expect actual &&
367 git commit-graph write --reachable &&
368 git -c core.commitGraph=false --no-replace-objects log >expect &&
369 git -c core.commitGraph=true --no-replace-objects log >actual &&
370 test_cmp expect actual &&
371 rm -rf .git/objects/info/commit-graph &&
372 git commit-graph write --reachable &&
373 test_path_is_file .git/objects/info/commit-graph
377 test_expect_success 'commit grafts invalidate commit-graph' '
378 cd "$TRASH_DIRECTORY" &&
379 test_when_finished rm -rf graft &&
380 git clone full graft &&
383 git commit-graph write --reachable &&
384 test_path_is_file .git/objects/info/commit-graph &&
385 H1=$(git rev-parse --verify HEAD~1) &&
386 H3=$(git rev-parse --verify HEAD~3) &&
387 echo "$H1 $H3" >.git/info/grafts &&
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_missing .git/objects/info/commit-graph
401 test_expect_success 'replace-objects invalidates commit-graph' '
402 cd "$TRASH_DIRECTORY" &&
403 test_when_finished rm -rf shallow &&
404 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
407 git commit-graph write --reachable &&
408 test_path_is_missing .git/objects/info/commit-graph &&
409 git fetch origin --unshallow &&
410 git commit-graph write --reachable &&
411 test_path_is_file .git/objects/info/commit-graph
415 # the verify tests below expect the commit-graph to contain
416 # exactly the commits reachable from the commits/8 branch.
417 # If the file changes the set of commits in the list, then the
418 # offsets into the binary file will result in different edits
419 # and the tests will likely break.
421 test_expect_success 'git commit-graph verify' '
422 cd "$TRASH_DIRECTORY/full" &&
423 git rev-parse commits/8 | git commit-graph write --stdin-commits &&
424 git commit-graph verify >output
429 HASH_LEN="$(test_oid rawsz)"
432 GRAPH_BYTE_CHUNK_COUNT=6
433 GRAPH_CHUNK_LOOKUP_OFFSET=8
434 GRAPH_CHUNK_LOOKUP_WIDTH=12
435 GRAPH_CHUNK_LOOKUP_ROWS=5
436 GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
437 GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
438 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
439 GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
440 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
441 GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
442 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
443 GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
444 GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
445 GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
446 GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
447 GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
448 GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
449 GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
450 GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
451 GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
452 GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
453 GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
454 GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
455 GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
456 GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
457 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
458 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
459 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
461 corrupt_graph_setup() {
462 cd "$TRASH_DIRECTORY/full" &&
463 test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
464 cp $objdir/info/commit-graph commit-graph-backup &&
465 chmod u+w $objdir/info/commit-graph
468 corrupt_graph_verify() {
470 test_must_fail git commit-graph verify 2>test_err &&
471 grep -v "^+" test_err >err &&
472 test_i18ngrep "$grepstr" err &&
473 if test "$2" != "no-copy"
475 cp $objdir/info/commit-graph commit-graph-pre-write-test
477 git status --short &&
478 GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git commit-graph write &&
479 chmod u+w $objdir/info/commit-graph &&
480 git commit-graph verify
483 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
484 # Manipulates the commit-graph file at the position
485 # by inserting the data, optionally zeroing the file
486 # starting at <zero_pos>, then runs 'git commit-graph verify'
487 # and places the output in the file 'err'. Test 'err' for
489 corrupt_graph_and_verify() {
493 corrupt_graph_setup &&
494 orig_size=$(wc -c < $objdir/info/commit-graph) &&
495 zero_pos=${4:-${orig_size}} &&
496 printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
497 dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
498 generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
499 corrupt_graph_verify "$grepstr"
503 test_expect_success POSIXPERM,SANITY 'detect permission problem' '
504 corrupt_graph_setup &&
505 chmod 000 $objdir/info/commit-graph &&
506 corrupt_graph_verify "Could not open" "no-copy"
509 test_expect_success 'detect too small' '
510 corrupt_graph_setup &&
511 echo "a small graph" >$objdir/info/commit-graph &&
512 corrupt_graph_verify "too small"
515 test_expect_success 'detect bad signature' '
516 corrupt_graph_and_verify 0 "\0" \
520 test_expect_success 'detect bad version' '
521 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
525 test_expect_success 'detect bad hash version' '
526 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
530 test_expect_success 'detect low chunk count' '
531 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\01" \
532 "missing the .* chunk"
535 test_expect_success 'detect missing OID fanout chunk' '
536 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
537 "missing the OID Fanout chunk"
540 test_expect_success 'detect missing OID lookup chunk' '
541 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
542 "missing the OID Lookup chunk"
545 test_expect_success 'detect missing commit data chunk' '
546 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
547 "missing the Commit Data chunk"
550 test_expect_success 'detect incorrect fanout' '
551 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
555 test_expect_success 'detect incorrect fanout final value' '
556 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
560 test_expect_success 'detect incorrect OID order' '
561 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
562 "incorrect OID order"
565 test_expect_success 'detect OID not in object database' '
566 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
567 "from object database"
570 test_expect_success 'detect incorrect tree OID' '
571 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
572 "root tree OID for commit"
575 test_expect_success 'detect incorrect parent int-id' '
576 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
580 test_expect_success 'detect extra parent int-id' '
581 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
585 test_expect_success 'detect wrong parent' '
586 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
587 "commit-graph parent for"
590 test_expect_success 'detect incorrect generation number' '
591 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
592 "generation for commit"
595 test_expect_success 'detect incorrect generation number' '
596 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
597 "non-zero generation number"
600 test_expect_success 'detect incorrect commit date' '
601 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
605 test_expect_success 'detect incorrect parent for octopus merge' '
606 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
610 test_expect_success 'detect invalid checksum hash' '
611 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
615 test_expect_success 'detect incorrect chunk count' '
616 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
617 "commit-graph file is too small to hold [0-9]* chunks" \
618 $GRAPH_CHUNK_LOOKUP_OFFSET
621 test_expect_success 'git fsck (checks commit-graph)' '
622 cd "$TRASH_DIRECTORY/full" &&
624 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
625 "incorrect checksum" &&
626 cp commit-graph-pre-write-test $objdir/info/commit-graph &&
627 test_must_fail git fsck
630 test_expect_success 'setup non-the_repository tests' '
633 test_commit -C repo one &&
634 test_commit -C repo two &&
635 git -C repo config core.commitGraph true &&
636 git -C repo rev-parse two | \
637 git -C repo commit-graph write --stdin-commits
640 test_expect_success 'parse_commit_in_graph works for non-the_repository' '
641 test-tool repository parse_commit_in_graph \
642 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
644 git -C repo log --pretty=format:"%ct " -1 &&
645 git -C repo rev-parse one
647 test_cmp expect actual &&
649 test-tool repository parse_commit_in_graph \
650 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
651 git -C repo log --pretty="%ct" -1 one >expect &&
652 test_cmp expect actual
655 test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
656 test-tool repository get_commit_tree_in_graph \
657 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
658 git -C repo rev-parse two^{tree} >expect &&
659 test_cmp expect actual &&
661 test-tool repository get_commit_tree_in_graph \
662 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
663 git -C repo rev-parse one^{tree} >expect &&
664 test_cmp expect actual
667 test_expect_success 'corrupt commit-graph write (broken parent)' '
672 empty="$(git mktree </dev/null)" &&
673 cat >broken <<-EOF &&
676 author whatever <whatever@example.com> 1234 -0000
677 committer whatever <whatever@example.com> 1234 -0000
681 broken="$(git hash-object -w -t commit --literally broken)" &&
682 git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
683 test_must_fail git commit-graph write --stdin-commits \
685 test_i18ngrep "unable to parse commit" test_err
689 test_expect_success 'corrupt commit-graph write (missing tree)' '
694 tree="$(git mktree </dev/null)" &&
695 cat >broken <<-EOF &&
697 author whatever <whatever@example.com> 1234 -0000
698 committer whatever <whatever@example.com> 1234 -0000
702 broken="$(git hash-object -w -t commit --literally broken)" &&
703 git commit-tree -p "$broken" -m "good" "$tree" >good &&
704 test_must_fail git commit-graph write --stdin-commits \
706 test_i18ngrep "unable to parse commit" test_err