tests/libgit2: don't overwrite config when testing conditionals

When testing conditional includes we overwrite the repository's config
file with the relevant conditions. This causes us to fully overwrite all
repository configuration, including the repository format version and
any extensions. While the test repository used in this test does not
have any extensions, we will add a reftable-enabled repository that does
rely on the "refStorage" extension eventually.

Fix this by only modifying the relevant config keys.
This commit is contained in:
Patrick Steinhardt
2025-07-29 09:28:19 +02:00
parent 5c5db73e3e
commit 1030b68f3d

View File

@@ -23,13 +23,15 @@ void test_config_conditionals__cleanup(void)
static void assert_condition_includes(const char *keyword, const char *path, bool expected)
{
git_buf value = GIT_BUF_INIT;
git_str key = GIT_STR_INIT;
git_str buf = GIT_STR_INIT;
git_config *cfg;
cl_git_pass(git_str_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
cl_git_pass(git_str_puts(&buf, "path = other\n"));
cl_git_pass(git_repository_config(&cfg, _repo));
cl_git_pass(git_str_printf(&key, "includeIf.%s:%s.path", keyword, path));
cl_git_pass(git_config_set_string(cfg, key.ptr, "other"));
git_config_free(cfg);
cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
_repo = cl_git_sandbox_reopen();
@@ -45,6 +47,9 @@ static void assert_condition_includes(const char *keyword, const char *path, boo
git_config_get_string_buf(&value, cfg, "foo.bar"));
}
cl_git_pass(git_config_delete_entry(cfg, key.ptr));
git_str_dispose(&key);
git_str_dispose(&buf);
git_buf_dispose(&value);
git_config_free(cfg);
@@ -157,10 +162,10 @@ void test_config_conditionals__empty(void)
git_str buf = GIT_STR_INIT;
git_config *cfg;
cl_git_pass(git_str_puts(&buf, "[includeIf]\n"));
cl_git_pass(git_str_puts(&buf, "path = other\n"));
cl_git_pass(git_repository_config(&cfg, _repo));
cl_git_pass(git_config_set_string(cfg, "includeIf.path", "other"));
git_config_free(cfg);
cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
_repo = cl_git_sandbox_reopen();