commit-graph: verify chains with --shallow mode
[gitweb.git] / t / t5324-split-commit-graph.sh
index 76068ee4077e6c2a4cfaf6ed24832b5f0f1f335f..3df90ae58f8beec94f7af080e399b2fda78874e9 100755 (executable)
@@ -169,4 +169,113 @@ test_expect_success 'create fork and chain across alternate' '
 
 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
 
+test_expect_success 'test merge stragety constants' '
+       git clone . merge-2 &&
+       (
+               cd merge-2 &&
+               git config core.commitGraph true &&
+               test_line_count = 2 $graphdir/commit-graph-chain &&
+               test_commit 14 &&
+               git commit-graph write --reachable --split --size-multiple=2 &&
+               test_line_count = 3 $graphdir/commit-graph-chain
+
+       ) &&
+       git clone . merge-10 &&
+       (
+               cd merge-10 &&
+               git config core.commitGraph true &&
+               test_line_count = 2 $graphdir/commit-graph-chain &&
+               test_commit 14 &&
+               git commit-graph write --reachable --split --size-multiple=10 &&
+               test_line_count = 1 $graphdir/commit-graph-chain &&
+               ls $graphdir/graph-*.graph >graph-files &&
+               test_line_count = 1 graph-files
+       ) &&
+       git clone . merge-10-expire &&
+       (
+               cd merge-10-expire &&
+               git config core.commitGraph true &&
+               test_line_count = 2 $graphdir/commit-graph-chain &&
+               test_commit 15 &&
+               git commit-graph write --reachable --split --size-multiple=10 --expire-time=1980-01-01 &&
+               test_line_count = 1 $graphdir/commit-graph-chain &&
+               ls $graphdir/graph-*.graph >graph-files &&
+               test_line_count = 3 graph-files
+       ) &&
+       git clone --no-hardlinks . max-commits &&
+       (
+               cd max-commits &&
+               git config core.commitGraph true &&
+               test_line_count = 2 $graphdir/commit-graph-chain &&
+               test_commit 16 &&
+               test_commit 17 &&
+               git commit-graph write --reachable --split --max-commits=1 &&
+               test_line_count = 1 $graphdir/commit-graph-chain &&
+               ls $graphdir/graph-*.graph >graph-files &&
+               test_line_count = 1 graph-files
+       )
+'
+
+corrupt_file() {
+       file=$1
+       pos=$2
+       data="${3:-\0}"
+       printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
+}
+
+test_expect_success 'verify hashes along chain, even in shallow' '
+       git clone --no-hardlinks . verify &&
+       (
+               cd verify &&
+               git commit-graph verify &&
+               base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
+               corrupt_file "$base_file" 1760 "\01" &&
+               test_must_fail git commit-graph verify --shallow 2>test_err &&
+               grep -v "^+" test_err >err &&
+               test_i18ngrep "incorrect checksum" err
+       )
+'
+
+test_expect_success 'verify --shallow does not check base contents' '
+       git clone --no-hardlinks . verify-shallow &&
+       (
+               cd verify-shallow &&
+               git commit-graph verify &&
+               base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
+               corrupt_file "$base_file" 1000 "\01" &&
+               git commit-graph verify --shallow &&
+               test_must_fail git commit-graph verify 2>test_err &&
+               grep -v "^+" test_err >err &&
+               test_i18ngrep "incorrect checksum" err
+       )
+'
+
+test_expect_success 'warn on base graph chunk incorrect' '
+       git clone --no-hardlinks . base-chunk &&
+       (
+               cd base-chunk &&
+               git commit-graph verify &&
+               base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
+               corrupt_file "$base_file" 1376 "\01" &&
+               git commit-graph verify --shallow 2>test_err &&
+               grep -v "^+" test_err >err &&
+               test_i18ngrep "commit-graph chain does not match" err
+       )
+'
+
+test_expect_success 'verify after commit-graph-chain corruption' '
+       git clone --no-hardlinks . verify-chain &&
+       (
+               cd verify-chain &&
+               corrupt_file "$graphdir/commit-graph-chain" 60 "G" &&
+               git commit-graph verify 2>test_err &&
+               grep -v "^+" test_err >err &&
+               test_i18ngrep "invalid commit-graph chain" err &&
+               corrupt_file "$graphdir/commit-graph-chain" 60 "A" &&
+               git commit-graph verify 2>test_err &&
+               grep -v "^+" test_err >err &&
+               test_i18ngrep "unable to find all commit-graph files" err
+       )
+'
+
 test_done