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 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
() {
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
78 NUM_CHUNKS
=$
((3 + $
(echo "$2" |
wc -w)))
81 header: 43475048 1 1 $NUM_CHUNKS 0
83 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
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
93 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
94 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
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 &&
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)
127 git branch commits/$i
129 git reset --hard commits/2 &&
130 for i in $(test_seq 6 7)
133 git branch commits/$i
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 &&
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_must_be_empty 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_must_be_empty err
165 test_expect_success
'commit-graph write --stdin-commits progress off for redirected stderr' '
166 cd "$TRASH_DIRECTORY/full" &&
167 git rev-parse commits/5 >in &&
168 git commit-graph write --stdin-commits <in 2>err &&
169 test_must_be_empty err
172 test_expect_success
'commit-graph write --stdin-commits force progress on for stderr' '
173 cd "$TRASH_DIRECTORY/full" &&
174 git rev-parse commits/5 >in &&
175 GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err &&
176 test_i18ngrep "Collecting commits from input" err
179 test_expect_success
'commit-graph write --stdin-commits with the --no-progress option' '
180 cd "$TRASH_DIRECTORY/full" &&
181 git rev-parse commits/5 >in &&
182 git commit-graph write --stdin-commits --no-progress <in 2>err &&
183 test_must_be_empty err
186 test_expect_success
'commit-graph verify progress off for redirected stderr' '
187 cd "$TRASH_DIRECTORY/full" &&
188 git commit-graph verify 2>err &&
189 test_must_be_empty err
192 test_expect_success
'commit-graph verify force progress on for stderr' '
193 cd "$TRASH_DIRECTORY/full" &&
194 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
195 test_file_not_empty err
198 test_expect_success
'commit-graph verify with the --no-progress option' '
199 cd "$TRASH_DIRECTORY/full" &&
200 git commit-graph verify --no-progress 2>err &&
201 test_must_be_empty err
204 # Current graph structure:
214 test_expect_success
'write graph with merges' '
215 cd "$TRASH_DIRECTORY/full" &&
216 git commit-graph write &&
217 test_path_is_file $objdir/info/commit-graph &&
218 graph_read_expect "10" "extra_edges"
221 graph_git_behavior
'merge 1 vs 2' full merge
/1 merge
/2
222 graph_git_behavior
'merge 1 vs 3' full merge
/1 merge
/3
223 graph_git_behavior
'merge 2 vs 3' full merge
/2 merge
/3
225 test_expect_success
'Add one more commit' '
226 cd "$TRASH_DIRECTORY/full" &&
228 git branch commits/8 &&
229 ls $objdir/pack | grep idx >existing-idx &&
231 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
234 # Current graph structure:
246 graph_git_behavior
'mixed mode, commit 8 vs merge 1' full commits
/8 merge
/1
247 graph_git_behavior
'mixed mode, commit 8 vs merge 2' full commits
/8 merge
/2
249 test_expect_success
'write graph with new commit' '
250 cd "$TRASH_DIRECTORY/full" &&
251 git commit-graph write &&
252 test_path_is_file $objdir/info/commit-graph &&
253 graph_read_expect "11" "extra_edges"
256 graph_git_behavior
'full graph, commit 8 vs merge 1' full commits
/8 merge
/1
257 graph_git_behavior
'full graph, commit 8 vs merge 2' full commits
/8 merge
/2
259 test_expect_success
'write graph with nothing new' '
260 cd "$TRASH_DIRECTORY/full" &&
261 git commit-graph write &&
262 test_path_is_file $objdir/info/commit-graph &&
263 graph_read_expect "11" "extra_edges"
266 graph_git_behavior
'cleared graph, commit 8 vs merge 1' full commits
/8 merge
/1
267 graph_git_behavior
'cleared graph, commit 8 vs merge 2' full commits
/8 merge
/2
269 test_expect_success
'build graph from latest pack with closure' '
270 cd "$TRASH_DIRECTORY/full" &&
271 cat new-idx | git commit-graph write --stdin-packs &&
272 test_path_is_file $objdir/info/commit-graph &&
273 graph_read_expect "9" "extra_edges"
276 graph_git_behavior
'graph from pack, commit 8 vs merge 1' full commits
/8 merge
/1
277 graph_git_behavior
'graph from pack, commit 8 vs merge 2' full commits
/8 merge
/2
279 test_expect_success
'build graph from commits with closure' '
280 cd "$TRASH_DIRECTORY/full" &&
281 git tag -a -m "merge" tag/merge merge/2 &&
282 git rev-parse tag/merge >commits-in &&
283 git rev-parse merge/1 >>commits-in &&
284 cat commits-in | git commit-graph write --stdin-commits &&
285 test_path_is_file $objdir/info/commit-graph &&
286 graph_read_expect "6"
289 graph_git_behavior
'graph from commits, commit 8 vs merge 1' full commits
/8 merge
/1
290 graph_git_behavior
'graph from commits, commit 8 vs merge 2' full commits
/8 merge
/2
292 test_expect_success
'build graph from commits with append' '
293 cd "$TRASH_DIRECTORY/full" &&
294 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
295 test_path_is_file $objdir/info/commit-graph &&
296 graph_read_expect "10" "extra_edges"
299 graph_git_behavior
'append graph, commit 8 vs merge 1' full commits
/8 merge
/1
300 graph_git_behavior
'append graph, commit 8 vs merge 2' full commits
/8 merge
/2
302 test_expect_success
'build graph using --reachable' '
303 cd "$TRASH_DIRECTORY/full" &&
304 git commit-graph write --reachable &&
305 test_path_is_file $objdir/info/commit-graph &&
306 graph_read_expect "11" "extra_edges"
309 graph_git_behavior
'append graph, commit 8 vs merge 1' full commits
/8 merge
/1
310 graph_git_behavior
'append graph, commit 8 vs merge 2' full commits
/8 merge
/2
312 test_expect_success
'setup bare repo' '
313 cd "$TRASH_DIRECTORY" &&
314 git clone --bare --no-local full bare &&
316 git config core.commitGraph true &&
320 graph_git_behavior
'bare repo, commit 8 vs merge 1' bare commits
/8 merge
/1
321 graph_git_behavior
'bare repo, commit 8 vs merge 2' bare commits
/8 merge
/2
323 test_expect_success
'write graph in bare repo' '
324 cd "$TRASH_DIRECTORY/bare" &&
325 git commit-graph write &&
326 test_path_is_file $baredir/info/commit-graph &&
327 graph_read_expect "11" "extra_edges"
330 graph_git_behavior
'bare repo with graph, commit 8 vs merge 1' bare commits
/8 merge
/1
331 graph_git_behavior
'bare repo with graph, commit 8 vs merge 2' bare commits
/8 merge
/2
333 test_expect_success
'perform fast-forward merge in full repo' '
334 cd "$TRASH_DIRECTORY/full" &&
335 git checkout -b merge-5-to-8 commits/5 &&
336 git merge commits/8 &&
337 git show-ref -s merge-5-to-8 >output &&
338 git show-ref -s commits/8 >expect &&
339 test_cmp expect output
342 test_expect_success
'check that gc computes commit-graph' '
343 cd "$TRASH_DIRECTORY/full" &&
344 git commit --allow-empty -m "blank" &&
345 git commit-graph write --reachable &&
346 cp $objdir/info/commit-graph commit-graph-before-gc &&
347 git reset --hard HEAD~1 &&
348 git config gc.writeCommitGraph true &&
350 cp $objdir/info/commit-graph commit-graph-after-gc &&
351 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
352 git commit-graph write --reachable &&
353 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
356 test_expect_success
'replace-objects invalidates commit-graph' '
357 cd "$TRASH_DIRECTORY" &&
358 test_when_finished rm -rf replace &&
359 git clone full replace &&
362 git commit-graph write --reachable &&
363 test_path_is_file .git/objects/info/commit-graph &&
364 git replace HEAD~1 HEAD~2 &&
365 git -c core.commitGraph=false log >expect &&
366 git -c core.commitGraph=true log >actual &&
367 test_cmp expect actual &&
368 git commit-graph write --reachable &&
369 git -c core.commitGraph=false --no-replace-objects log >expect &&
370 git -c core.commitGraph=true --no-replace-objects log >actual &&
371 test_cmp expect actual &&
372 rm -rf .git/objects/info/commit-graph &&
373 git commit-graph write --reachable &&
374 test_path_is_file .git/objects/info/commit-graph
378 test_expect_success
'commit grafts invalidate commit-graph' '
379 cd "$TRASH_DIRECTORY" &&
380 test_when_finished rm -rf graft &&
381 git clone full graft &&
384 git commit-graph write --reachable &&
385 test_path_is_file .git/objects/info/commit-graph &&
386 H1=$(git rev-parse --verify HEAD~1) &&
387 H3=$(git rev-parse --verify HEAD~3) &&
388 echo "$H1 $H3" >.git/info/grafts &&
389 git -c core.commitGraph=false log >expect &&
390 git -c core.commitGraph=true log >actual &&
391 test_cmp expect actual &&
392 git commit-graph write --reachable &&
393 git -c core.commitGraph=false --no-replace-objects log >expect &&
394 git -c core.commitGraph=true --no-replace-objects log >actual &&
395 test_cmp expect actual &&
396 rm -rf .git/objects/info/commit-graph &&
397 git commit-graph write --reachable &&
398 test_path_is_missing .git/objects/info/commit-graph
402 test_expect_success
'replace-objects invalidates commit-graph' '
403 cd "$TRASH_DIRECTORY" &&
404 test_when_finished rm -rf shallow &&
405 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
408 git commit-graph write --reachable &&
409 test_path_is_missing .git/objects/info/commit-graph &&
410 git fetch origin --unshallow &&
411 git commit-graph write --reachable &&
412 test_path_is_file .git/objects/info/commit-graph
416 # the verify tests below expect the commit-graph to contain
417 # exactly the commits reachable from the commits/8 branch.
418 # If the file changes the set of commits in the list, then the
419 # offsets into the binary file will result in different edits
420 # and the tests will likely break.
422 test_expect_success
'git commit-graph verify' '
423 cd "$TRASH_DIRECTORY/full" &&
424 git rev-parse commits/8 | git commit-graph write --stdin-commits &&
425 git commit-graph verify >output
430 HASH_LEN
="$(test_oid rawsz)"
433 GRAPH_BYTE_CHUNK_COUNT
=6
434 GRAPH_CHUNK_LOOKUP_OFFSET
=8
435 GRAPH_CHUNK_LOOKUP_WIDTH
=12
436 GRAPH_CHUNK_LOOKUP_ROWS
=5
437 GRAPH_BYTE_OID_FANOUT_ID
=$GRAPH_CHUNK_LOOKUP_OFFSET
438 GRAPH_BYTE_OID_LOOKUP_ID
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
439 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
440 GRAPH_BYTE_COMMIT_DATA_ID
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
441 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
442 GRAPH_FANOUT_OFFSET
=$
(($GRAPH_CHUNK_LOOKUP_OFFSET + \
443 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
444 GRAPH_BYTE_FANOUT1
=$
(($GRAPH_FANOUT_OFFSET + 4 * 4))
445 GRAPH_BYTE_FANOUT2
=$
(($GRAPH_FANOUT_OFFSET + 4 * 255))
446 GRAPH_OID_LOOKUP_OFFSET
=$
(($GRAPH_FANOUT_OFFSET + 4 * 256))
447 GRAPH_BYTE_OID_LOOKUP_ORDER
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
448 GRAPH_BYTE_OID_LOOKUP_MISSING
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
449 GRAPH_COMMIT_DATA_OFFSET
=$
(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
450 GRAPH_BYTE_COMMIT_TREE
=$GRAPH_COMMIT_DATA_OFFSET
451 GRAPH_BYTE_COMMIT_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
452 GRAPH_BYTE_COMMIT_EXTRA_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
453 GRAPH_BYTE_COMMIT_WRONG_PARENT
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
454 GRAPH_BYTE_COMMIT_GENERATION
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
455 GRAPH_BYTE_COMMIT_DATE
=$
(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
456 GRAPH_COMMIT_DATA_WIDTH
=$
(($HASH_LEN + 16))
457 GRAPH_OCTOPUS_DATA_OFFSET
=$
(($GRAPH_COMMIT_DATA_OFFSET + \
458 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
459 GRAPH_BYTE_OCTOPUS
=$
(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
460 GRAPH_BYTE_FOOTER
=$
(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
462 corrupt_graph_setup
() {
463 cd "$TRASH_DIRECTORY/full" &&
464 test_when_finished
mv commit-graph-backup
$objdir/info
/commit-graph
&&
465 cp $objdir/info
/commit-graph commit-graph-backup
&&
466 chmod u
+w
$objdir/info
/commit-graph
469 corrupt_graph_verify
() {
471 test_must_fail git commit-graph verify
2>test_err
&&
472 grep -v "^+" test_err
>err
&&
473 test_i18ngrep
"$grepstr" err
&&
474 if test "$2" != "no-copy"
476 cp $objdir/info
/commit-graph commit-graph-pre-write-test
478 git status
--short &&
479 GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD
=true git commit-graph
write &&
480 chmod u
+w
$objdir/info
/commit-graph
&&
481 git commit-graph verify
484 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
485 # Manipulates the commit-graph file at the position
486 # by inserting the data, optionally zeroing the file
487 # starting at <zero_pos>, then runs 'git commit-graph verify'
488 # and places the output in the file 'err'. Test 'err' for
490 corrupt_graph_and_verify
() {
494 corrupt_graph_setup
&&
495 orig_size
=$
(wc -c < $objdir/info
/commit-graph
) &&
496 zero_pos
=${4:-${orig_size}} &&
497 printf "$data" |
dd of
="$objdir/info/commit-graph" bs
=1 seek
="$pos" conv
=notrunc
&&
498 dd of
="$objdir/info/commit-graph" bs
=1 seek
="$zero_pos" if=/dev
/null
&&
499 generate_zero_bytes $
(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
500 corrupt_graph_verify
"$grepstr"
504 test_expect_success POSIXPERM
,SANITY
'detect permission problem' '
505 corrupt_graph_setup &&
506 chmod 000 $objdir/info/commit-graph &&
507 corrupt_graph_verify "Could not open" "no-copy"
510 test_expect_success
'detect too small' '
511 corrupt_graph_setup &&
512 echo "a small graph" >$objdir/info/commit-graph &&
513 corrupt_graph_verify "too small"
516 test_expect_success
'detect bad signature' '
517 corrupt_graph_and_verify 0 "\0" \
521 test_expect_success
'detect bad version' '
522 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
526 test_expect_success
'detect bad hash version' '
527 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
531 test_expect_success
'detect low chunk count' '
532 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
533 "missing the .* chunk"
536 test_expect_success
'detect missing OID fanout chunk' '
537 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
538 "missing the OID Fanout chunk"
541 test_expect_success
'detect missing OID lookup chunk' '
542 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
543 "missing the OID Lookup chunk"
546 test_expect_success
'detect missing commit data chunk' '
547 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
548 "missing the Commit Data chunk"
551 test_expect_success
'detect incorrect fanout' '
552 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
556 test_expect_success
'detect incorrect fanout final value' '
557 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
561 test_expect_success
'detect incorrect OID order' '
562 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
563 "incorrect OID order"
566 test_expect_success
'detect OID not in object database' '
567 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
568 "from object database"
571 test_expect_success
'detect incorrect tree OID' '
572 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
573 "root tree OID for commit"
576 test_expect_success
'detect incorrect parent int-id' '
577 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
581 test_expect_success
'detect extra parent int-id' '
582 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
586 test_expect_success
'detect wrong parent' '
587 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
588 "commit-graph parent for"
591 test_expect_success
'detect incorrect generation number' '
592 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
593 "generation for commit"
596 test_expect_success
'detect incorrect generation number' '
597 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
598 "non-zero generation number"
601 test_expect_success
'detect incorrect commit date' '
602 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
606 test_expect_success
'detect incorrect parent for octopus merge' '
607 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
611 test_expect_success
'detect invalid checksum hash' '
612 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
616 test_expect_success
'detect incorrect chunk count' '
617 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
618 "chunk lookup table entry missing" $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