diff --git a/builtin/config.c b/builtin/config.c index cf4ba0f7cc6f22..97bb16ceb93dbc 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1618,6 +1618,12 @@ int cmd_config(int argc, */ argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage, PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); + if (startup_info->have_repository) { + repo_config(repo, git_default_config, NULL); + prepare_repo_settings(repo); + repo->settings.command_requires_full_index = 0; + } + if (subcommand) { argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage, PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index d98cb4ac113c67..477899dc0a193a 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -2573,4 +2573,67 @@ test_expect_success 'sparse-index is not expanded: merge-ours' ' ensure_not_expanded merge -s ours merge-right ' +test_expect_success 'sparse-index is not expanded: config --blob with index path' ' + init_repos && + + # Stage valid config blobs at in-cone locations. + for repo in full-checkout sparse-checkout sparse-index + do + test_write_lines "[test]" "value = root" \ + >"$repo/test-config" && + git -C "$repo" add test-config && + test_write_lines "[test]" "value = deep" \ + >"$repo/deep/test-config" && + git -C "$repo" add deep/test-config || return 1 + done && + + # Nonexistent file: must not expand. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + test_must_fail \ + git -C sparse-index config --blob ":.lfsconfig" -l && + test_region ! index ensure_full_index trace2.txt && + + # Root-level file (always in-cone): must not expand, and must + # successfully parse the config values. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index config --blob ":test-config" -l >actual && + echo "test.value=root" >expect && + test_cmp expect actual && + test_region ! index ensure_full_index trace2.txt && + + # File inside sparse cone (deep/): must not expand. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index config --blob ":deep/test-config" -l >actual && + echo "test.value=deep" >expect && + test_cmp expect actual && + test_region ! index ensure_full_index trace2.txt && + + # File outside sparse cone (folder1/a): must expand because + # it is behind a sparse directory entry. The blob contains + # "a\n" from the initial setup, which git config parses as + # a valueless key. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index config --blob ":folder1/a" -l && + test_region index ensure_full_index trace2.txt +' + +test_expect_success 'config --file and --blob do not expand sparse index' ' + init_repos && + + test_write_lines "[test]" "value = external" >external-config && + + # --file reads an external config file; the sparse index + # should not be read or expanded. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index config --file ../external-config -l >actual && + echo "test.value=external" >expect && + test_cmp expect actual && + test_region ! index ensure_full_index trace2.txt +' + test_done