Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t5324-split-commit-graph.sh
blob77e91547ea32433854f6ca3417749f7cfec4197b
1 #!/bin/sh
3 test_description='split commit graph'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-chunk.sh
9 GIT_TEST_COMMIT_GRAPH=0
10 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
12 test_expect_success 'setup repo' '
13 git init &&
14 git config core.commitGraph true &&
15 git config gc.writeCommitGraph false &&
16 objdir=".git/objects" &&
17 infodir="$objdir/info" &&
18 graphdir="$infodir/commit-graphs" &&
19 test_oid_cache <<-EOM
20 shallow sha1:2132
21 shallow sha256:2436
23 base sha1:1408
24 base sha256:1528
26 oid_version sha1:1
27 oid_version sha256:2
28 EOM
31 graph_read_expect() {
32 NUM_BASE=0
33 if test ! -z $2
34 then
35 NUM_BASE=$2
37 OPTIONS=
38 if test -z "$3"
39 then
40 OPTIONS=" read_generation_data"
42 cat >expect <<- EOF
43 header: 43475048 1 $(test_oid oid_version) 4 $NUM_BASE
44 num_commits: $1
45 chunks: oid_fanout oid_lookup commit_metadata generation_data
46 options:$OPTIONS
47 EOF
48 test-tool read-graph >output &&
49 test_cmp expect output
52 test_expect_success POSIXPERM 'tweak umask for modebit tests' '
53 umask 022
56 test_expect_success 'create commits and write commit-graph' '
57 for i in $(test_seq 3)
59 test_commit $i &&
60 git branch commits/$i || return 1
61 done &&
62 git commit-graph write --reachable &&
63 test_path_is_file $infodir/commit-graph &&
64 graph_read_expect 3
67 graph_git_two_modes() {
68 git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output &&
69 git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect &&
70 test_cmp expect output
73 graph_git_behavior() {
74 MSG=$1
75 BRANCH=$2
76 COMPARE=$3
77 DIR=$4
78 test_expect_success "check normal git operations: $MSG" '
79 graph_git_two_modes "log --oneline $BRANCH" "$DIR" &&
80 graph_git_two_modes "log --topo-order $BRANCH" "$DIR" &&
81 graph_git_two_modes "log --graph $COMPARE..$BRANCH" "$DIR" &&
82 graph_git_two_modes "branch -vv" "$DIR" &&
83 graph_git_two_modes "merge-base -a $BRANCH $COMPARE" "$DIR"
87 graph_git_behavior 'graph exists' commits/3 commits/1
89 verify_chain_files_exist() {
90 for hash in $(cat $1/commit-graph-chain)
92 test_path_is_file $1/graph-$hash.graph || return 1
93 done
96 test_expect_success 'add more commits, and write a new base graph' '
97 git reset --hard commits/1 &&
98 for i in $(test_seq 4 5)
100 test_commit $i &&
101 git branch commits/$i || return 1
102 done &&
103 git reset --hard commits/2 &&
104 for i in $(test_seq 6 10)
106 test_commit $i &&
107 git branch commits/$i || return 1
108 done &&
109 git reset --hard commits/2 &&
110 git merge commits/4 &&
111 git branch merge/1 &&
112 git reset --hard commits/4 &&
113 git merge commits/6 &&
114 git branch merge/2 &&
115 git commit-graph write --reachable &&
116 graph_read_expect 12
119 test_expect_success 'fork and fail to base a chain on a commit-graph file' '
120 test_when_finished rm -rf fork &&
121 git clone . fork &&
123 cd fork &&
124 rm .git/objects/info/commit-graph &&
125 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
126 test_commit new-commit &&
127 git commit-graph write --reachable --split &&
128 test_path_is_file $graphdir/commit-graph-chain &&
129 test_line_count = 1 $graphdir/commit-graph-chain &&
130 verify_chain_files_exist $graphdir
134 test_expect_success 'add three more commits, write a tip graph' '
135 git reset --hard commits/3 &&
136 git merge merge/1 &&
137 git merge commits/5 &&
138 git merge merge/2 &&
139 git branch merge/3 &&
140 git commit-graph write --reachable --split &&
141 test_path_is_missing $infodir/commit-graph &&
142 test_path_is_file $graphdir/commit-graph-chain &&
143 ls $graphdir/graph-*.graph >graph-files &&
144 test_line_count = 2 graph-files &&
145 verify_chain_files_exist $graphdir
148 graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
150 test_expect_success 'add one commit, write a tip graph' '
151 test_commit 11 &&
152 git branch commits/11 &&
153 git commit-graph write --reachable --split &&
154 test_path_is_missing $infodir/commit-graph &&
155 test_path_is_file $graphdir/commit-graph-chain &&
156 ls $graphdir/graph-*.graph >graph-files &&
157 test_line_count = 3 graph-files &&
158 verify_chain_files_exist $graphdir
161 graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
163 test_expect_success 'add one commit, write a merged graph' '
164 test_commit 12 &&
165 git branch commits/12 &&
166 git commit-graph write --reachable --split &&
167 test_path_is_file $graphdir/commit-graph-chain &&
168 test_line_count = 2 $graphdir/commit-graph-chain &&
169 ls $graphdir/graph-*.graph >graph-files &&
170 test_line_count = 2 graph-files &&
171 verify_chain_files_exist $graphdir
174 graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
176 test_expect_success 'create fork and chain across alternate' '
177 git clone . fork &&
179 cd fork &&
180 git config core.commitGraph true &&
181 rm -rf $graphdir &&
182 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
183 test_commit 13 &&
184 git branch commits/13 &&
185 git commit-graph write --reachable --split &&
186 test_path_is_file $graphdir/commit-graph-chain &&
187 test_line_count = 3 $graphdir/commit-graph-chain &&
188 ls $graphdir/graph-*.graph >graph-files &&
189 test_line_count = 1 graph-files &&
190 git -c core.commitGraph=true rev-list HEAD >expect &&
191 git -c core.commitGraph=false rev-list HEAD >actual &&
192 test_cmp expect actual &&
193 test_commit 14 &&
194 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
195 test_line_count = 3 $graphdir/commit-graph-chain &&
196 ls $graphdir/graph-*.graph >graph-files &&
197 test_line_count = 1 graph-files
201 if test -d fork
202 then
203 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork"
206 test_expect_success 'test merge stragety constants' '
207 git clone . merge-2 &&
209 cd merge-2 &&
210 git config core.commitGraph true &&
211 test_line_count = 2 $graphdir/commit-graph-chain &&
212 test_commit 14 &&
213 git commit-graph write --reachable --split --size-multiple=2 &&
214 test_line_count = 3 $graphdir/commit-graph-chain
216 ) &&
217 git clone . merge-10 &&
219 cd merge-10 &&
220 git config core.commitGraph true &&
221 test_line_count = 2 $graphdir/commit-graph-chain &&
222 test_commit 14 &&
223 git commit-graph write --reachable --split --size-multiple=10 &&
224 test_line_count = 1 $graphdir/commit-graph-chain &&
225 ls $graphdir/graph-*.graph >graph-files &&
226 test_line_count = 1 graph-files
227 ) &&
228 git clone . merge-10-expire &&
230 cd merge-10-expire &&
231 git config core.commitGraph true &&
232 test_line_count = 2 $graphdir/commit-graph-chain &&
233 test_commit 15 &&
234 touch $graphdir/to-delete.graph $graphdir/to-keep.graph &&
235 test-tool chmtime =1546362000 $graphdir/to-delete.graph &&
236 test-tool chmtime =1546362001 $graphdir/to-keep.graph &&
237 git commit-graph write --reachable --split --size-multiple=10 \
238 --expire-time="2019-01-01 12:00 -05:00" &&
239 test_line_count = 1 $graphdir/commit-graph-chain &&
240 test_path_is_missing $graphdir/to-delete.graph &&
241 test_path_is_file $graphdir/to-keep.graph &&
242 ls $graphdir/graph-*.graph >graph-files &&
243 test_line_count = 3 graph-files
244 ) &&
245 git clone --no-hardlinks . max-commits &&
247 cd max-commits &&
248 git config core.commitGraph true &&
249 test_line_count = 2 $graphdir/commit-graph-chain &&
250 test_commit 16 &&
251 test_commit 17 &&
252 git commit-graph write --reachable --split --max-commits=1 &&
253 test_line_count = 1 $graphdir/commit-graph-chain &&
254 ls $graphdir/graph-*.graph >graph-files &&
255 test_line_count = 1 graph-files
259 test_expect_success 'remove commit-graph-chain file after flattening' '
260 git clone . flatten &&
262 cd flatten &&
263 test_line_count = 2 $graphdir/commit-graph-chain &&
264 git commit-graph write --reachable &&
265 test_path_is_missing $graphdir/commit-graph-chain &&
266 ls $graphdir >graph-files &&
267 test_line_count = 0 graph-files
271 corrupt_file() {
272 file=$1
273 pos=$2
274 data="${3:-\0}"
275 chmod a+w "$file" &&
276 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
279 test_expect_success 'verify hashes along chain, even in shallow' '
280 git clone --no-hardlinks . verify &&
282 cd verify &&
283 git commit-graph verify &&
284 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
285 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
286 test_must_fail git commit-graph verify --shallow 2>test_err &&
287 grep -v "^+" test_err >err &&
288 test_grep "incorrect checksum" err
292 test_expect_success 'verify notices chain slice which is bogus (base)' '
293 git clone --no-hardlinks . verify-chain-bogus-base &&
295 cd verify-chain-bogus-base &&
296 git commit-graph verify &&
297 base_file=$graphdir/graph-$(sed -n 1p $graphdir/commit-graph-chain).graph &&
298 echo "garbage" >$base_file &&
299 test_must_fail git commit-graph verify 2>test_err &&
300 grep -v "^+" test_err >err &&
301 grep "commit-graph file is too small" err
305 test_expect_success 'verify notices chain slice which is bogus (tip)' '
306 git clone --no-hardlinks . verify-chain-bogus-tip &&
308 cd verify-chain-bogus-tip &&
309 git commit-graph verify &&
310 tip_file=$graphdir/graph-$(sed -n 2p $graphdir/commit-graph-chain).graph &&
311 echo "garbage" >$tip_file &&
312 test_must_fail git commit-graph verify 2>test_err &&
313 grep -v "^+" test_err >err &&
314 grep "commit-graph file is too small" err
318 test_expect_success 'verify --shallow does not check base contents' '
319 git clone --no-hardlinks . verify-shallow &&
321 cd verify-shallow &&
322 git commit-graph verify &&
323 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
324 corrupt_file "$base_file" 1500 "\01" &&
325 git commit-graph verify --shallow &&
326 test_must_fail git commit-graph verify 2>test_err &&
327 grep -v "^+" test_err >err &&
328 test_grep "incorrect checksum" err
332 test_expect_success 'warn on base graph chunk incorrect' '
333 git clone --no-hardlinks . base-chunk &&
335 cd base-chunk &&
336 git commit-graph verify &&
337 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
338 corrupt_file "$base_file" $(test_oid base) "\01" &&
339 test_must_fail git commit-graph verify --shallow 2>test_err &&
340 grep -v "^+" test_err >err &&
341 test_grep "commit-graph chain does not match" err
345 test_expect_success 'verify after commit-graph-chain corruption (base)' '
346 git clone --no-hardlinks . verify-chain-base &&
348 cd verify-chain-base &&
349 corrupt_file "$graphdir/commit-graph-chain" 30 "G" &&
350 test_must_fail git commit-graph verify 2>test_err &&
351 grep -v "^+" test_err >err &&
352 test_grep "invalid commit-graph chain" err &&
353 corrupt_file "$graphdir/commit-graph-chain" 30 "A" &&
354 test_must_fail git commit-graph verify 2>test_err &&
355 grep -v "^+" test_err >err &&
356 test_grep "unable to find all commit-graph files" err
360 test_expect_success 'verify after commit-graph-chain corruption (tip)' '
361 git clone --no-hardlinks . verify-chain-tip &&
363 cd verify-chain-tip &&
364 corrupt_file "$graphdir/commit-graph-chain" 70 "G" &&
365 test_must_fail git commit-graph verify 2>test_err &&
366 grep -v "^+" test_err >err &&
367 test_grep "invalid commit-graph chain" err &&
368 corrupt_file "$graphdir/commit-graph-chain" 70 "A" &&
369 test_must_fail git commit-graph verify 2>test_err &&
370 grep -v "^+" test_err >err &&
371 test_grep "unable to find all commit-graph files" err
375 test_expect_success 'verify notices too-short chain file' '
376 git clone --no-hardlinks . verify-chain-short &&
378 cd verify-chain-short &&
379 git commit-graph verify &&
380 echo "garbage" >$graphdir/commit-graph-chain &&
381 test_must_fail git commit-graph verify 2>test_err &&
382 grep -v "^+" test_err >err &&
383 grep "commit-graph chain file too small" err
387 test_expect_success 'verify across alternates' '
388 git clone --no-hardlinks . verify-alt &&
390 cd verify-alt &&
391 rm -rf $graphdir &&
392 altdir="$(pwd)/../.git/objects" &&
393 echo "$altdir" >.git/objects/info/alternates &&
394 git commit-graph verify --object-dir="$altdir/" &&
395 test_commit extra &&
396 git commit-graph write --reachable --split &&
397 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
398 corrupt_file "$tip_file" 1500 "\01" &&
399 test_must_fail git commit-graph verify --shallow 2>test_err &&
400 grep -v "^+" test_err >err &&
401 test_grep "incorrect checksum" err
405 test_expect_success 'reader bounds-checks base-graph chunk' '
406 git clone --no-hardlinks . corrupt-base-chunk &&
408 cd corrupt-base-chunk &&
409 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
410 corrupt_chunk_file "$tip_file" BASE clear 01020304 &&
411 git -c core.commitGraph=false log >expect.out &&
412 git -c core.commitGraph=true log >out 2>err &&
413 test_cmp expect.out out &&
414 grep "commit-graph base graphs chunk is too small" err
418 test_expect_success 'add octopus merge' '
419 git reset --hard commits/10 &&
420 git merge commits/3 commits/4 &&
421 git branch merge/octopus &&
422 git commit-graph write --reachable --split &&
423 git commit-graph verify --progress 2>err &&
424 test_line_count = 1 err &&
425 grep "Verifying commits in commit graph: 100% (18/18)" err &&
426 test_grep ! warning err &&
427 test_line_count = 3 $graphdir/commit-graph-chain
430 graph_git_behavior 'graph exists' merge/octopus commits/12
432 test_expect_success 'split across alternate where alternate is not split' '
433 git commit-graph write --reachable &&
434 test_path_is_file .git/objects/info/commit-graph &&
435 cp .git/objects/info/commit-graph . &&
436 git clone --no-hardlinks . alt-split &&
438 cd alt-split &&
439 rm -f .git/objects/info/commit-graph &&
440 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
441 test_commit 18 &&
442 git commit-graph write --reachable --split &&
443 test_line_count = 1 $graphdir/commit-graph-chain
444 ) &&
445 test_cmp commit-graph .git/objects/info/commit-graph
448 test_expect_success '--split=no-merge always writes an incremental' '
449 test_when_finished rm -rf a b &&
450 rm -rf $graphdir $infodir/commit-graph &&
451 git reset --hard commits/2 &&
452 git rev-list HEAD~1 >a &&
453 git rev-list HEAD >b &&
454 git commit-graph write --split --stdin-commits <a &&
455 git commit-graph write --split=no-merge --stdin-commits <b &&
456 test_line_count = 2 $graphdir/commit-graph-chain
459 test_expect_success '--split=replace replaces the chain' '
460 rm -rf $graphdir $infodir/commit-graph &&
461 git reset --hard commits/3 &&
462 git rev-list -1 HEAD~2 >a &&
463 git rev-list -1 HEAD~1 >b &&
464 git rev-list -1 HEAD >c &&
465 git commit-graph write --split=no-merge --stdin-commits <a &&
466 git commit-graph write --split=no-merge --stdin-commits <b &&
467 git commit-graph write --split=no-merge --stdin-commits <c &&
468 test_line_count = 3 $graphdir/commit-graph-chain &&
469 git commit-graph write --stdin-commits --split=replace <b &&
470 test_path_is_missing $infodir/commit-graph &&
471 test_path_is_file $graphdir/commit-graph-chain &&
472 ls $graphdir/graph-*.graph >graph-files &&
473 test_line_count = 1 graph-files &&
474 verify_chain_files_exist $graphdir &&
475 graph_read_expect 2
478 test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion' '
479 git init ulimit &&
481 cd ulimit &&
482 for i in $(test_seq 64)
484 test_commit $i &&
485 run_with_limited_open_files test_might_fail git commit-graph write \
486 --split=no-merge --reachable || return 1
487 done
491 while read mode modebits
493 test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" '
494 rm -rf $graphdir $infodir/commit-graph &&
495 git reset --hard commits/1 &&
496 test_config core.sharedrepository "$mode" &&
497 git commit-graph write --split --reachable &&
498 ls $graphdir/graph-*.graph >graph-files &&
499 test_line_count = 1 graph-files &&
500 echo "$modebits" >expect &&
501 test_modebits $graphdir/graph-*.graph >actual &&
502 test_cmp expect actual &&
503 test_modebits $graphdir/commit-graph-chain >actual &&
504 test_cmp expect actual
506 done <<\EOF
507 0666 -r--r--r--
508 0600 -r--------
511 test_expect_success '--split=replace with partial Bloom data' '
512 rm -rf $graphdir $infodir/commit-graph &&
513 git reset --hard commits/3 &&
514 git rev-list -1 HEAD~2 >a &&
515 git rev-list -1 HEAD~1 >b &&
516 git commit-graph write --split=no-merge --stdin-commits --changed-paths <a &&
517 git commit-graph write --split=no-merge --stdin-commits <b &&
518 git commit-graph write --split=replace --stdin-commits --changed-paths <c &&
519 ls $graphdir/graph-*.graph >graph-files &&
520 test_line_count = 1 graph-files &&
521 verify_chain_files_exist $graphdir
524 test_expect_success 'prevent regression for duplicate commits across layers' '
525 git init dup &&
526 git -C dup commit --allow-empty -m one &&
527 git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
528 test_grep "attempting to write a commit-graph" err &&
529 git -C dup commit-graph write --split=no-merge --reachable &&
530 git -C dup commit --allow-empty -m two &&
531 git -C dup commit-graph write --split=no-merge --reachable &&
532 git -C dup commit --allow-empty -m three &&
533 git -C dup commit-graph write --split --reachable &&
534 git -C dup commit-graph verify
537 NUM_FIRST_LAYER_COMMITS=64
538 NUM_SECOND_LAYER_COMMITS=16
539 NUM_THIRD_LAYER_COMMITS=7
540 NUM_FOURTH_LAYER_COMMITS=8
541 NUM_FIFTH_LAYER_COMMITS=16
542 SECOND_LAYER_SEQUENCE_START=$(($NUM_FIRST_LAYER_COMMITS + 1))
543 SECOND_LAYER_SEQUENCE_END=$(($SECOND_LAYER_SEQUENCE_START + $NUM_SECOND_LAYER_COMMITS - 1))
544 THIRD_LAYER_SEQUENCE_START=$(($SECOND_LAYER_SEQUENCE_END + 1))
545 THIRD_LAYER_SEQUENCE_END=$(($THIRD_LAYER_SEQUENCE_START + $NUM_THIRD_LAYER_COMMITS - 1))
546 FOURTH_LAYER_SEQUENCE_START=$(($THIRD_LAYER_SEQUENCE_END + 1))
547 FOURTH_LAYER_SEQUENCE_END=$(($FOURTH_LAYER_SEQUENCE_START + $NUM_FOURTH_LAYER_COMMITS - 1))
548 FIFTH_LAYER_SEQUENCE_START=$(($FOURTH_LAYER_SEQUENCE_END + 1))
549 FIFTH_LAYER_SEQUENCE_END=$(($FIFTH_LAYER_SEQUENCE_START + $NUM_FIFTH_LAYER_COMMITS - 1))
551 # Current split graph chain:
553 # 16 commits (No GDAT)
554 # ------------------------
555 # 64 commits (GDAT)
557 test_expect_success 'setup repo for mixed generation commit-graph-chain' '
558 graphdir=".git/objects/info/commit-graphs" &&
559 test_oid_cache <<-EOF &&
560 oid_version sha1:1
561 oid_version sha256:2
563 git init mixed &&
565 cd mixed &&
566 git config core.commitGraph true &&
567 git config gc.writeCommitGraph false &&
568 for i in $(test_seq $NUM_FIRST_LAYER_COMMITS)
570 test_commit $i &&
571 git branch commits/$i || return 1
572 done &&
573 git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
574 graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
575 test_line_count = 1 $graphdir/commit-graph-chain &&
576 for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END)
578 test_commit $i &&
579 git branch commits/$i || return 1
580 done &&
581 git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
582 test_line_count = 2 $graphdir/commit-graph-chain &&
583 test-tool read-graph >output &&
584 cat >expect <<-EOF &&
585 header: 43475048 1 $(test_oid oid_version) 4 1
586 num_commits: $NUM_SECOND_LAYER_COMMITS
587 chunks: oid_fanout oid_lookup commit_metadata
588 options:
590 test_cmp expect output &&
591 git commit-graph verify &&
592 cat $graphdir/commit-graph-chain
596 # The new layer will be added without generation data chunk as it was not
597 # present on the layer underneath it.
599 # 7 commits (No GDAT)
600 # ------------------------
601 # 16 commits (No GDAT)
602 # ------------------------
603 # 64 commits (GDAT)
605 test_expect_success 'do not write generation data chunk if not present on existing tip' '
606 git clone mixed mixed-no-gdat &&
608 cd mixed-no-gdat &&
609 for i in $(test_seq $THIRD_LAYER_SEQUENCE_START $THIRD_LAYER_SEQUENCE_END)
611 test_commit $i &&
612 git branch commits/$i || return 1
613 done &&
614 git commit-graph write --reachable --split=no-merge &&
615 test_line_count = 3 $graphdir/commit-graph-chain &&
616 test-tool read-graph >output &&
617 cat >expect <<-EOF &&
618 header: 43475048 1 $(test_oid oid_version) 4 2
619 num_commits: $NUM_THIRD_LAYER_COMMITS
620 chunks: oid_fanout oid_lookup commit_metadata
621 options:
623 test_cmp expect output &&
624 git commit-graph verify
628 # Number of commits in each layer of the split-commit graph before merge:
630 # 8 commits (No GDAT)
631 # ------------------------
632 # 7 commits (No GDAT)
633 # ------------------------
634 # 16 commits (No GDAT)
635 # ------------------------
636 # 64 commits (GDAT)
638 # The top two layers are merged and do not have generation data chunk as layer below them does
639 # not have generation data chunk.
641 # 15 commits (No GDAT)
642 # ------------------------
643 # 16 commits (No GDAT)
644 # ------------------------
645 # 64 commits (GDAT)
647 test_expect_success 'do not write generation data chunk if the topmost remaining layer does not have generation data chunk' '
648 git clone mixed-no-gdat mixed-merge-no-gdat &&
650 cd mixed-merge-no-gdat &&
651 for i in $(test_seq $FOURTH_LAYER_SEQUENCE_START $FOURTH_LAYER_SEQUENCE_END)
653 test_commit $i &&
654 git branch commits/$i || return 1
655 done &&
656 git commit-graph write --reachable --split --size-multiple 1 &&
657 test_line_count = 3 $graphdir/commit-graph-chain &&
658 test-tool read-graph >output &&
659 cat >expect <<-EOF &&
660 header: 43475048 1 $(test_oid oid_version) 4 2
661 num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS))
662 chunks: oid_fanout oid_lookup commit_metadata
663 options:
665 test_cmp expect output &&
666 git commit-graph verify
670 # Number of commits in each layer of the split-commit graph before merge:
672 # 16 commits (No GDAT)
673 # ------------------------
674 # 15 commits (No GDAT)
675 # ------------------------
676 # 16 commits (No GDAT)
677 # ------------------------
678 # 64 commits (GDAT)
680 # The top three layers are merged and has generation data chunk as the topmost remaining layer
681 # has generation data chunk.
683 # 47 commits (GDAT)
684 # ------------------------
685 # 64 commits (GDAT)
687 test_expect_success 'write generation data chunk if topmost remaining layer has generation data chunk' '
688 git clone mixed-merge-no-gdat mixed-merge-gdat &&
690 cd mixed-merge-gdat &&
691 for i in $(test_seq $FIFTH_LAYER_SEQUENCE_START $FIFTH_LAYER_SEQUENCE_END)
693 test_commit $i &&
694 git branch commits/$i || return 1
695 done &&
696 git commit-graph write --reachable --split --size-multiple 1 &&
697 test_line_count = 2 $graphdir/commit-graph-chain &&
698 test-tool read-graph >output &&
699 cat >expect <<-EOF &&
700 header: 43475048 1 $(test_oid oid_version) 5 1
701 num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS))
702 chunks: oid_fanout oid_lookup commit_metadata generation_data
703 options: read_generation_data
705 test_cmp expect output
709 test_expect_success 'write generation data chunk when commit-graph chain is replaced' '
710 git clone mixed mixed-replace &&
712 cd mixed-replace &&
713 git commit-graph write --reachable --split=replace &&
714 test_path_is_file $graphdir/commit-graph-chain &&
715 test_line_count = 1 $graphdir/commit-graph-chain &&
716 verify_chain_files_exist $graphdir &&
717 graph_read_expect $(($NUM_FIRST_LAYER_COMMITS + $NUM_SECOND_LAYER_COMMITS)) &&
718 git commit-graph verify
722 test_expect_success 'temporary graph layer is discarded upon failure' '
723 git init layer-discard &&
725 cd layer-discard &&
727 test_commit A &&
728 test_commit B &&
730 # Intentionally remove commit "A" from the object store
731 # so that the commit-graph machinery fails to parse the
732 # parents of "B".
734 # This takes place after the commit-graph machinery has
735 # initialized a new temporary file to store the contents
736 # of the new graph layer, so will allow us to ensure
737 # that the temporary file is discarded upon failure.
738 rm $objdir/$(test_oid_to_path $(git rev-parse HEAD^)) &&
740 test_must_fail git commit-graph write --reachable --split &&
741 test_dir_is_empty $graphdir
745 test_done