commit-graph: verify required chunks are present
[gitweb.git] / t / t5318-commit-graph.sh
index a380419b65bdf1ecace4c23831e76bc8a7d81962..dc16849ddd5530287768123391e0d3e692489ad8 100755 (executable)
@@ -11,6 +11,11 @@ test_expect_success 'setup full repo' '
        objdir=".git/objects"
 '
 
+test_expect_success 'verify graph with no graph file' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git commit-graph verify
+'
+
 test_expect_success 'write graph with no packs' '
        cd "$TRASH_DIRECTORY/full" &&
        git commit-graph write --object-dir . &&
@@ -28,8 +33,8 @@ test_expect_success 'create commits and repack' '
 '
 
 graph_git_two_modes() {
-       git -c core.graph=true $1 >output
-       git -c core.graph=false $1 >expect
+       git -c core.commitGraph=true $1 >output
+       git -c core.commitGraph=false $1 >expect
        test_cmp output expect
 }
 
@@ -221,4 +226,90 @@ test_expect_success 'write graph in bare repo' '
 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
 
+test_expect_success 'perform fast-forward merge in full repo' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git checkout -b merge-5-to-8 commits/5 &&
+       git merge commits/8 &&
+       git show-ref -s merge-5-to-8 >output &&
+       git show-ref -s commits/8 >expect &&
+       test_cmp expect output
+'
+
+# the verify tests below expect the commit-graph to contain
+# exactly the commits reachable from the commits/8 branch.
+# If the file changes the set of commits in the list, then the
+# offsets into the binary file will result in different edits
+# and the tests will likely break.
+
+test_expect_success 'git commit-graph verify' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git rev-parse commits/8 | git commit-graph write --stdin-commits &&
+       git commit-graph verify >output
+'
+
+GRAPH_BYTE_VERSION=4
+GRAPH_BYTE_HASH=5
+GRAPH_BYTE_CHUNK_COUNT=6
+GRAPH_CHUNK_LOOKUP_OFFSET=8
+GRAPH_CHUNK_LOOKUP_WIDTH=12
+GRAPH_CHUNK_LOOKUP_ROWS=5
+GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
+GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
+                           1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
+GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
+                            2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
+
+# usage: corrupt_graph_and_verify <position> <data> <string>
+# Manipulates the commit-graph file at the position
+# by inserting the data, then runs 'git commit-graph verify'
+# and places the output in the file 'err'. Test 'err' for
+# the given string.
+corrupt_graph_and_verify() {
+       pos=$1
+       data="${2:-\0}"
+       grepstr=$3
+       cd "$TRASH_DIRECTORY/full" &&
+       test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
+       cp $objdir/info/commit-graph commit-graph-backup &&
+       printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
+       test_must_fail git commit-graph verify 2>test_err &&
+       grep -v "^+" test_err >err
+       test_i18ngrep "$grepstr" err
+}
+
+test_expect_success 'detect bad signature' '
+       corrupt_graph_and_verify 0 "\0" \
+               "graph signature"
+'
+
+test_expect_success 'detect bad version' '
+       corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
+               "graph version"
+'
+
+test_expect_success 'detect bad hash version' '
+       corrupt_graph_and_verify $GRAPH_BYTE_HASH "\02" \
+               "hash version"
+'
+
+test_expect_success 'detect low chunk count' '
+       corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
+               "missing the .* chunk"
+'
+
+test_expect_success 'detect missing OID fanout chunk' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
+               "missing the OID Fanout chunk"
+'
+
+test_expect_success 'detect missing OID lookup chunk' '
+       corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
+               "missing the OID Lookup chunk"
+'
+
+test_expect_success 'detect missing commit data chunk' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
+               "missing the Commit Data chunk"
+'
+
 test_done