Skip to content

Commit 6698e05

Browse files
committed
Fix the test and comment.
1 parent f140950 commit 6698e05

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/config/read.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,34 @@ void test_config_read__bom(void)
759759
git_buf_dispose(&buf);
760760
}
761761

762+
static int read_nosection_cb(const git_config_entry *entry, void *payload) {
763+
int *seen = (int*)payload;
764+
if (strcmp(entry->name, "key") == 0) {
765+
(*seen)++;
766+
}
767+
return 0;
768+
}
769+
762770
/* This would ideally issue a warning, if we had a way to do so. */
763771
void test_config_read__nosection(void)
764772
{
765773
git_config *cfg;
766774
git_buf buf = GIT_BUF_INIT;
775+
int seen = 0;
767776

768777
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-nosection")));
769778

770-
cl_git_pass(git_config_get_string_buf(&buf, cfg, "key"));
771-
cl_assert_equal_s(buf.ptr, "value");
779+
/*
780+
* Given a key with no section, we do not allow reading it,
781+
* but we do include it in an iteration over the config
782+
* store. This appears to match how git's own APIs (and
783+
* git-config(1)) behave.
784+
*/
785+
786+
cl_git_fail_with(git_config_get_string_buf(&buf, cfg, "key"), GIT_EINVALIDSPEC);
787+
788+
cl_git_pass(git_config_foreach(cfg, read_nosection_cb, &seen));
789+
cl_assert_equal_i(seen, 1);
772790

773791
git_buf_dispose(&buf);
774792
git_config_free(cfg);

0 commit comments

Comments
 (0)