Skip to content

Commit 1030b68

Browse files
committed
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.
1 parent 5c5db73 commit 1030b68

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

tests/libgit2/config/conditionals.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ void test_config_conditionals__cleanup(void)
2323
static void assert_condition_includes(const char *keyword, const char *path, bool expected)
2424
{
2525
git_buf value = GIT_BUF_INIT;
26+
git_str key = GIT_STR_INIT;
2627
git_str buf = GIT_STR_INIT;
2728
git_config *cfg;
2829

29-
cl_git_pass(git_str_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
30-
cl_git_pass(git_str_puts(&buf, "path = other\n"));
30+
cl_git_pass(git_repository_config(&cfg, _repo));
31+
cl_git_pass(git_str_printf(&key, "includeIf.%s:%s.path", keyword, path));
32+
cl_git_pass(git_config_set_string(cfg, key.ptr, "other"));
33+
git_config_free(cfg);
3134

32-
cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
3335
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
3436
_repo = cl_git_sandbox_reopen();
3537

@@ -45,6 +47,9 @@ static void assert_condition_includes(const char *keyword, const char *path, boo
4547
git_config_get_string_buf(&value, cfg, "foo.bar"));
4648
}
4749

50+
cl_git_pass(git_config_delete_entry(cfg, key.ptr));
51+
52+
git_str_dispose(&key);
4853
git_str_dispose(&buf);
4954
git_buf_dispose(&value);
5055
git_config_free(cfg);
@@ -157,10 +162,10 @@ void test_config_conditionals__empty(void)
157162
git_str buf = GIT_STR_INIT;
158163
git_config *cfg;
159164

160-
cl_git_pass(git_str_puts(&buf, "[includeIf]\n"));
161-
cl_git_pass(git_str_puts(&buf, "path = other\n"));
165+
cl_git_pass(git_repository_config(&cfg, _repo));
166+
cl_git_pass(git_config_set_string(cfg, "includeIf.path", "other"));
167+
git_config_free(cfg);
162168

163-
cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
164169
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
165170
_repo = cl_git_sandbox_reopen();
166171

0 commit comments

Comments
 (0)