Merge branch 'en/t3031-title-fix'
[gitweb.git] / t / t5318-commit-graph.sh
index a0cf1f66de64eb8941ce485ec7c654c33c63bb56..4f17d7701e456bbb0992efdba2861e1dac8f7c23 100755 (executable)
@@ -205,6 +205,16 @@ test_expect_success 'build graph from commits with append' '
 graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
 graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
 
+test_expect_success 'build graph using --reachable' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git commit-graph write --reachable &&
+       test_path_is_file $objdir/info/commit-graph &&
+       graph_read_expect "11" "large_edges"
+'
+
+graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
+graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
+
 test_expect_success 'setup bare repo' '
        cd "$TRASH_DIRECTORY" &&
        git clone --bare --no-local full bare &&
@@ -235,6 +245,20 @@ test_expect_success 'perform fast-forward merge in full repo' '
        test_cmp expect output
 '
 
+test_expect_success 'check that gc computes commit-graph' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git commit --allow-empty -m "blank" &&
+       git commit-graph write --reachable &&
+       cp $objdir/info/commit-graph commit-graph-before-gc &&
+       git reset --hard HEAD~1 &&
+       git config gc.writeCommitGraph true &&
+       git gc &&
+       cp $objdir/info/commit-graph commit-graph-after-gc &&
+       ! test_cmp commit-graph-before-gc commit-graph-after-gc &&
+       git commit-graph write --reachable &&
+       test_cmp commit-graph-after-gc $objdir/info/commit-graph
+'
+
 # 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
@@ -279,6 +303,7 @@ GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
 GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
                             $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
+GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
 
 # usage: corrupt_graph_and_verify <position> <data> <string>
 # Manipulates the commit-graph file at the position
@@ -393,4 +418,52 @@ test_expect_success 'detect incorrect parent for octopus merge' '
                "invalid parent"
 '
 
+test_expect_success 'detect invalid checksum hash' '
+       corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
+               "incorrect checksum"
+'
+
+test_expect_success 'git fsck (checks commit-graph)' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git fsck &&
+       corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
+               "incorrect checksum" &&
+       test_must_fail git fsck
+'
+
+test_expect_success 'setup non-the_repository tests' '
+       rm -rf repo &&
+       git init repo &&
+       test_commit -C repo one &&
+       test_commit -C repo two &&
+       git -C repo config core.commitGraph true &&
+       git -C repo rev-parse two | \
+               git -C repo commit-graph write --stdin-commits
+'
+
+test_expect_success 'parse_commit_in_graph works for non-the_repository' '
+       test-tool repository parse_commit_in_graph \
+               repo/.git repo "$(git -C repo rev-parse two)" >actual &&
+       echo $(git -C repo log --pretty="%ct" -1) \
+               $(git -C repo rev-parse one) >expect &&
+       test_cmp expect actual &&
+
+       test-tool repository parse_commit_in_graph \
+               repo/.git repo "$(git -C repo rev-parse one)" >actual &&
+       echo $(git -C repo log --pretty="%ct" -1 one) >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
+       test-tool repository get_commit_tree_in_graph \
+               repo/.git repo "$(git -C repo rev-parse two)" >actual &&
+       echo $(git -C repo rev-parse two^{tree}) >expect &&
+       test_cmp expect actual &&
+
+       test-tool repository get_commit_tree_in_graph \
+               repo/.git repo "$(git -C repo rev-parse one)" >actual &&
+       echo $(git -C repo rev-parse one^{tree}) >expect &&
+       test_cmp expect actual
+'
+
 test_done