]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsck: verify commit graph when implicitly enabled
authorGlen Choo <chooglen@google.com>
Fri, 15 Oct 2021 20:16:29 +0000 (13:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Oct 2021 21:30:07 +0000 (14:30 -0700)
Change fsck to check the "core_commit_graph" variable set in
"repo-settings.c" instead of reading the "core.commitGraph" variable.
This fixes a bug where we wouldn't verify the commit-graph if the
config key was missing. This bug was introduced in
31b1de6a09 (commit-graph: turn on commit-graph by default, 2019-08-13),
where core.commitGraph was turned on by default.

Add tests to "t5318-commit-graph.sh" to verify that fsck checks the
commit-graph as expected for the 3 values of core.commitGraph. Also,
disable GIT_TEST_COMMIT_GRAPH in t/t0410-partial-clone.sh because some
test cases use fsck in ways that assume that commit-graph checking is
disabled.

Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsck.c
t/t0410-partial-clone.sh
t/t5318-commit-graph.sh

index b42b6fe21f7347b546d53e8f6a250e50659befe3..1c4e485b66dc3cf862599989fd8f0d73b28fc9d8 100644 (file)
@@ -803,6 +803,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
                fsck_enable_object_names(&fsck_walk_options);
 
        git_config(git_fsck_config, &fsck_obj_options);
+       prepare_repo_settings(the_repository);
 
        if (connectivity_only) {
                for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
@@ -908,7 +909,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 
        check_connectivity();
 
-       if (!git_config_get_bool("core.commitgraph", &i) && i) {
+       if (the_repository->settings.core_commit_graph) {
                struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
                const char *verify_argv[] = { "commit-graph", "verify", NULL, NULL, NULL };
 
index bba679685f68cfcd9f75ab41f48603f07315e1f9..c76485b1b60fe3292fdc55d99fe5c576660dffb9 100755 (executable)
@@ -6,6 +6,10 @@ test_description='partial clone'
 
 # missing promisor objects cause repacks which write bitmaps to fail
 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
+# When enabled, some commands will write commit-graphs. This causes fsck
+# to fail when delete_object() is called because fsck will attempt to
+# verify the out-of-sync commit graph.
+GIT_TEST_COMMIT_GRAPH=0
 
 delete_object () {
        rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
@@ -322,7 +326,7 @@ test_expect_success 'rev-list stops traversal at missing and promised commit' '
 
        git -C repo config core.repositoryformatversion 1 &&
        git -C repo config extensions.partialclone "arbitrary string" &&
-       GIT_TEST_COMMIT_GRAPH=0 git -C repo -c core.commitGraph=false rev-list --exclude-promisor-objects --objects bar >out &&
+       git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
        grep $(git -C repo rev-parse bar) out &&
        ! grep $FOO out
 '
index 84d122a7ae7a0271d1e1e9c9c74ec4aee8f72cae..f516fda7cc934dc7672f0e0765206461a01df51e 100755 (executable)
@@ -694,12 +694,33 @@ test_expect_success 'detect incorrect chunk count' '
                $GRAPH_CHUNK_LOOKUP_OFFSET
 '
 
-test_expect_success 'git fsck (checks commit-graph)' '
+test_expect_success 'git fsck (checks commit-graph when config set to true)' '
        cd "$TRASH_DIRECTORY/full" &&
        git fsck &&
        corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
                "incorrect checksum" &&
        cp commit-graph-pre-write-test $objdir/info/commit-graph &&
+       test_must_fail git -c core.commitGraph=true fsck
+'
+
+test_expect_success 'git fsck (ignores commit-graph when config set to false)' '
+       cd "$TRASH_DIRECTORY/full" &&
+       git fsck &&
+       corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
+               "incorrect checksum" &&
+       cp commit-graph-pre-write-test $objdir/info/commit-graph &&
+       git -c core.commitGraph=false fsck
+'
+
+test_expect_success 'git fsck (checks commit-graph when config unset)' '
+       cd "$TRASH_DIRECTORY/full" &&
+       test_when_finished "git config core.commitGraph true" &&
+
+       git fsck &&
+       corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
+               "incorrect checksum" &&
+       test_unconfig core.commitGraph &&
+       cp commit-graph-pre-write-test $objdir/info/commit-graph &&
        test_must_fail git fsck
 '