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" &&
17 test_expect_success POSIXPERM 'tweak umask for modebit tests' '
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)
49 test_expect_success 'exit with correct error on bad input to --stdin-commits' '
50 cd "$TRASH_DIRECTORY/full" &&
51 echo HEAD | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr &&
52 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
53 # valid tree OID, but not a commit OID
54 git rev-parse HEAD^{tree} | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr &&
55 test_i18ngrep "invalid commit object id" stderr
58 graph_git_two_modes() {
59 git -c core.commitGraph=true $1 >output
60 git -c core.commitGraph=false $1 >expect
61 test_cmp expect output
64 graph_git_behavior() {
69 test_expect_success "check normal git operations: $MSG" '
70 cd "$TRASH_DIRECTORY/$DIR" &&
71 graph_git_two_modes "log --oneline $BRANCH" &&
72 graph_git_two_modes "log --topo-order $BRANCH" &&
73 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
74 graph_git_two_modes "branch -vv" &&
75 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
79 graph_git_behavior 'no graph' full commits/3 commits/1
87 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
90 header: 43475048 1 1 $NUM_CHUNKS 0
92 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
94 test-tool read-graph >output &&
95 test_cmp expect output
98 test_expect_success 'write graph' '
99 cd "$TRASH_DIRECTORY/full" &&
100 git commit-graph write &&
101 test_path_is_file $objdir/info/commit-graph &&
102 graph_read_expect "3"
105 test_expect_success POSIXPERM 'write graph has correct permissions' '
106 test_path_is_file $objdir/info/commit-graph &&
107 echo "-r--r--r--" >expect &&
108 test_modebits $objdir/info/commit-graph >actual &&
109 test_cmp expect actual
112 graph_git_behavior 'graph exists' full commits/3 commits/1
114 test_expect_success 'Add more commits' '
115 cd "$TRASH_DIRECTORY/full" &&
116 git reset --hard commits/1 &&
117 for i in $(test_seq 4 5)
120 git branch commits/$i
122 git reset --hard commits/2 &&
123 for i in $(test_seq 6 7)
126 git branch commits/$i
128 git reset --hard commits/2 &&
129 git merge commits/4 &&
130 git branch merge/1 &&
131 git reset --hard commits/4 &&
132 git merge commits/6 &&
133 git branch merge/2 &&
134 git reset --hard commits/3 &&
135 git merge commits/5 commits/7 &&
136 git branch merge/3 &&
140 test_expect_success 'commit-graph write progress off for redirected stderr' '
141 cd "$TRASH_DIRECTORY/full" &&
142 git commit-graph write 2>err &&
143 test_must_be_empty err
146 test_expect_success 'commit-graph write force progress on for stderr' '
147 cd "$TRASH_DIRECTORY/full" &&
148 GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
149 test_file_not_empty err
152 test_expect_success 'commit-graph write with the --no-progress option' '
153 cd "$TRASH_DIRECTORY/full" &&
154 git commit-graph write --no-progress 2>err &&
155 test_must_be_empty err
158 test_expect_success 'commit-graph write --stdin-commits progress off for redirected stderr' '
159 cd "$TRASH_DIRECTORY/full" &&
160 git rev-parse commits/5 >in &&
161 git commit-graph write --stdin-commits <in 2>err &&
162 test_must_be_empty err
165 test_expect_success 'commit-graph write --stdin-commits force progress on for stderr' '
166 cd "$TRASH_DIRECTORY/full" &&
167 git rev-parse commits/5 >in &&
168 GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err &&
169 test_i18ngrep "Collecting commits from input" err
172 test_expect_success 'commit-graph write --stdin-commits with the --no-progress option' '
173 cd "$TRASH_DIRECTORY/full" &&
174 git rev-parse commits/5 >in &&
175 git commit-graph write --stdin-commits --no-progress <in 2>err &&
176 test_must_be_empty err
179 test_expect_success 'commit-graph verify progress off for redirected stderr' '
180 cd "$TRASH_DIRECTORY/full" &&
181 git commit-graph verify 2>err &&
182 test_must_be_empty err
185 test_expect_success 'commit-graph verify force progress on for stderr' '
186 cd "$TRASH_DIRECTORY/full" &&
187 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
188 test_file_not_empty err
191 test_expect_success 'commit-graph verify with the --no-progress option' '
192 cd "$TRASH_DIRECTORY/full" &&
193 git commit-graph verify --no-progress 2>err &&
194 test_must_be_empty err
197 # Current graph structure:
207 test_expect_success 'write graph with merges' '
208 cd "$TRASH_DIRECTORY/full" &&
209 git commit-graph write &&
210 test_path_is_file $objdir/info/commit-graph &&
211 graph_read_expect "10" "extra_edges"
214 graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
215 graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
216 graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
218 test_expect_success 'Add one more commit' '
219 cd "$TRASH_DIRECTORY/full" &&
221 git branch commits/8 &&
222 ls $objdir/pack | grep idx >existing-idx &&
224 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
227 # Current graph structure:
239 graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
240 graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
242 test_expect_success 'write graph with new commit' '
243 cd "$TRASH_DIRECTORY/full" &&
244 git commit-graph write &&
245 test_path_is_file $objdir/info/commit-graph &&
246 graph_read_expect "11" "extra_edges"
249 graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
250 graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
252 test_expect_success 'write graph with nothing new' '
253 cd "$TRASH_DIRECTORY/full" &&
254 git commit-graph write &&
255 test_path_is_file $objdir/info/commit-graph &&
256 graph_read_expect "11" "extra_edges"
259 graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
260 graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
262 test_expect_success 'build graph from latest pack with closure' '
263 cd "$TRASH_DIRECTORY/full" &&
264 cat new-idx | git commit-graph write --stdin-packs &&
265 test_path_is_file $objdir/info/commit-graph &&
266 graph_read_expect "9" "extra_edges"
269 graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
270 graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
272 test_expect_success 'build graph from commits with closure' '
273 cd "$TRASH_DIRECTORY/full" &&
274 git tag -a -m "merge" tag/merge merge/2 &&
275 git rev-parse tag/merge >commits-in &&
276 git rev-parse merge/1 >>commits-in &&
277 cat commits-in | git commit-graph write --stdin-commits &&
278 test_path_is_file $objdir/info/commit-graph &&
279 graph_read_expect "6"
282 graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
283 graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
285 test_expect_success 'build graph from commits with append' '
286 cd "$TRASH_DIRECTORY/full" &&
287 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
288 test_path_is_file $objdir/info/commit-graph &&
289 graph_read_expect "10" "extra_edges"
292 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
293 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
295 test_expect_success 'build graph using --reachable' '
296 cd "$TRASH_DIRECTORY/full" &&
297 git commit-graph write --reachable &&
298 test_path_is_file $objdir/info/commit-graph &&
299 graph_read_expect "11" "extra_edges"
302 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
303 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
305 test_expect_success 'setup bare repo' '
306 cd "$TRASH_DIRECTORY" &&
307 git clone --bare --no-local full bare &&
309 git config core.commitGraph true &&
313 graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
314 graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
316 test_expect_success 'write graph in bare repo' '
317 cd "$TRASH_DIRECTORY/bare" &&
318 git commit-graph write &&
319 test_path_is_file $baredir/info/commit-graph &&
320 graph_read_expect "11" "extra_edges"
323 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
324 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
326 test_expect_success 'perform fast-forward merge in full repo' '
327 cd "$TRASH_DIRECTORY/full" &&
328 git checkout -b merge-5-to-8 commits/5 &&
329 git merge commits/8 &&
330 git show-ref -s merge-5-to-8 >output &&
331 git show-ref -s commits/8 >expect &&
332 test_cmp expect output
335 test_expect_success 'check that gc computes commit-graph' '
336 cd "$TRASH_DIRECTORY/full" &&
337 git commit --allow-empty -m "blank" &&
338 git commit-graph write --reachable &&
339 cp $objdir/info/commit-graph commit-graph-before-gc &&
340 git reset --hard HEAD~1 &&
341 git config gc.writeCommitGraph true &&
343 cp $objdir/info/commit-graph commit-graph-after-gc &&
344 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
345 git commit-graph write --reachable &&
346 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
349 test_expect_success 'replace-objects invalidates commit-graph' '
350 cd "$TRASH_DIRECTORY" &&
351 test_when_finished rm -rf replace &&
352 git clone full replace &&
355 git commit-graph write --reachable &&
356 test_path_is_file .git/objects/info/commit-graph &&
357 git replace HEAD~1 HEAD~2 &&
358 git -c core.commitGraph=false log >expect &&
359 git -c core.commitGraph=true log >actual &&
360 test_cmp expect actual &&
361 git commit-graph write --reachable &&
362 git -c core.commitGraph=false --no-replace-objects log >expect &&
363 git -c core.commitGraph=true --no-replace-objects log >actual &&
364 test_cmp expect actual &&
365 rm -rf .git/objects/info/commit-graph &&
366 git commit-graph write --reachable &&
367 test_path_is_file .git/objects/info/commit-graph
371 test_expect_success 'commit grafts invalidate commit-graph' '
372 cd "$TRASH_DIRECTORY" &&
373 test_when_finished rm -rf graft &&
374 git clone full graft &&
377 git commit-graph write --reachable &&
378 test_path_is_file .git/objects/info/commit-graph &&
379 H1=$(git rev-parse --verify HEAD~1) &&
380 H3=$(git rev-parse --verify HEAD~3) &&
381 echo "$H1 $H3" >.git/info/grafts &&
382 git -c core.commitGraph=false log >expect &&
383 git -c core.commitGraph=true log >actual &&
384 test_cmp expect actual &&
385 git commit-graph write --reachable &&
386 git -c core.commitGraph=false --no-replace-objects log >expect &&
387 git -c core.commitGraph=true --no-replace-objects log >actual &&
388 test_cmp expect actual &&
389 rm -rf .git/objects/info/commit-graph &&
390 git commit-graph write --reachable &&
391 test_path_is_missing .git/objects/info/commit-graph
395 test_expect_success 'replace-objects invalidates commit-graph' '
396 cd "$TRASH_DIRECTORY" &&
397 test_when_finished rm -rf shallow &&
398 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
401 git commit-graph write --reachable &&
402 test_path_is_missing .git/objects/info/commit-graph &&
403 git fetch origin --unshallow &&
404 git commit-graph write --reachable &&
405 test_path_is_file .git/objects/info/commit-graph
409 # the verify tests below expect the commit-graph to contain
410 # exactly the commits reachable from the commits/8 branch.
411 # If the file changes the set of commits in the list, then the
412 # offsets into the binary file will result in different edits
413 # and the tests will likely break.
415 test_expect_success 'git commit-graph verify' '
416 cd "$TRASH_DIRECTORY/full" &&
417 git rev-parse commits/8 | git commit-graph write --stdin-commits &&
418 git commit-graph verify >output
423 HASH_LEN="$(test_oid rawsz)"
426 GRAPH_BYTE_CHUNK_COUNT=6
427 GRAPH_CHUNK_LOOKUP_OFFSET=8
428 GRAPH_CHUNK_LOOKUP_WIDTH=12
429 GRAPH_CHUNK_LOOKUP_ROWS=5
430 GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
431 GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
432 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
433 GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
434 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
435 GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
436 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
437 GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
438 GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
439 GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
440 GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
441 GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
442 GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
443 GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
444 GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
445 GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
446 GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
447 GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
448 GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
449 GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
450 GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
451 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
452 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
453 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
455 corrupt_graph_setup() {
456 cd "$TRASH_DIRECTORY/full" &&
457 test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
458 cp $objdir/info/commit-graph commit-graph-backup &&
459 chmod u+w $objdir/info/commit-graph
462 corrupt_graph_verify() {
464 test_must_fail git commit-graph verify 2>test_err &&
465 grep -v "^+" test_err >err &&
466 test_i18ngrep "$grepstr" err &&
467 if test "$2" != "no-copy"
469 cp $objdir/info/commit-graph commit-graph-pre-write-test
471 git status --short &&
472 GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
473 chmod u+w $objdir/info/commit-graph &&
474 git commit-graph verify
477 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
478 # Manipulates the commit-graph file at the position
479 # by inserting the data, optionally zeroing the file
480 # starting at <zero_pos>, then runs 'git commit-graph verify'
481 # and places the output in the file 'err'. Test 'err' for
483 corrupt_graph_and_verify() {
487 corrupt_graph_setup &&
488 orig_size=$(wc -c < $objdir/info/commit-graph) &&
489 zero_pos=${4:-${orig_size}} &&
490 printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
491 dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
492 generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
493 corrupt_graph_verify "$grepstr"
497 test_expect_success POSIXPERM,SANITY 'detect permission problem' '
498 corrupt_graph_setup &&
499 chmod 000 $objdir/info/commit-graph &&
500 corrupt_graph_verify "Could not open" "no-copy"
503 test_expect_success 'detect too small' '
504 corrupt_graph_setup &&
505 echo "a small graph" >$objdir/info/commit-graph &&
506 corrupt_graph_verify "too small"
509 test_expect_success 'detect bad signature' '
510 corrupt_graph_and_verify 0 "\0" \
514 test_expect_success 'detect bad version' '
515 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
519 test_expect_success 'detect bad hash version' '
520 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
524 test_expect_success 'detect low chunk count' '
525 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
526 "missing the .* chunk"
529 test_expect_success 'detect missing OID fanout chunk' '
530 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
531 "missing the OID Fanout chunk"
534 test_expect_success 'detect missing OID lookup chunk' '
535 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
536 "missing the OID Lookup chunk"
539 test_expect_success 'detect missing commit data chunk' '
540 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
541 "missing the Commit Data chunk"
544 test_expect_success 'detect incorrect fanout' '
545 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
549 test_expect_success 'detect incorrect fanout final value' '
550 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
554 test_expect_success 'detect incorrect OID order' '
555 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
556 "incorrect OID order"
559 test_expect_success 'detect OID not in object database' '
560 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
561 "from object database"
564 test_expect_success 'detect incorrect tree OID' '
565 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
566 "root tree OID for commit"
569 test_expect_success 'detect incorrect parent int-id' '
570 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
574 test_expect_success 'detect extra parent int-id' '
575 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
579 test_expect_success 'detect wrong parent' '
580 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
581 "commit-graph parent for"
584 test_expect_success 'detect incorrect generation number' '
585 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
586 "generation for commit"
589 test_expect_success 'detect incorrect generation number' '
590 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
591 "non-zero generation number"
594 test_expect_success 'detect incorrect commit date' '
595 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
599 test_expect_success 'detect incorrect parent for octopus merge' '
600 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
604 test_expect_success 'detect invalid checksum hash' '
605 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
609 test_expect_success 'detect incorrect chunk count' '
610 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
611 "chunk lookup table entry missing" $GRAPH_CHUNK_LOOKUP_OFFSET
614 test_expect_success 'git fsck (checks commit-graph)' '
615 cd "$TRASH_DIRECTORY/full" &&
617 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
618 "incorrect checksum" &&
619 cp commit-graph-pre-write-test $objdir/info/commit-graph &&
620 test_must_fail git fsck
623 test_expect_success 'setup non-the_repository tests' '
626 test_commit -C repo one &&
627 test_commit -C repo two &&
628 git -C repo config core.commitGraph true &&
629 git -C repo rev-parse two | \
630 git -C repo commit-graph write --stdin-commits
633 test_expect_success 'parse_commit_in_graph works for non-the_repository' '
634 test-tool repository parse_commit_in_graph \
635 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
637 git -C repo log --pretty=format:"%ct " -1 &&
638 git -C repo rev-parse one
640 test_cmp expect actual &&
642 test-tool repository parse_commit_in_graph \
643 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
644 git -C repo log --pretty="%ct" -1 one >expect &&
645 test_cmp expect actual
648 test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
649 test-tool repository get_commit_tree_in_graph \
650 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
651 git -C repo rev-parse two^{tree} >expect &&
652 test_cmp expect actual &&
654 test-tool repository get_commit_tree_in_graph \
655 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
656 git -C repo rev-parse one^{tree} >expect &&
657 test_cmp expect actual
660 test_expect_success 'corrupt commit-graph write (broken parent)' '
665 empty="$(git mktree </dev/null)" &&
666 cat >broken <<-EOF &&
669 author whatever <whatever@example.com> 1234 -0000
670 committer whatever <whatever@example.com> 1234 -0000
674 broken="$(git hash-object -w -t commit --literally broken)" &&
675 git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
676 test_must_fail git commit-graph write --stdin-commits \
678 test_i18ngrep "unable to parse commit" test_err
682 test_expect_success 'corrupt commit-graph write (missing tree)' '
687 tree="$(git mktree </dev/null)" &&
688 cat >broken <<-EOF &&
690 author whatever <whatever@example.com> 1234 -0000
691 committer whatever <whatever@example.com> 1234 -0000
695 broken="$(git hash-object -w -t commit --literally broken)" &&
696 git commit-tree -p "$broken" -m "good" "$tree" >good &&
697 test_must_fail git commit-graph write --stdin-commits \
699 test_i18ngrep "unable to parse commit" test_err