]> git.proxmox.com Git - libgit2.git/blob - tests/config/config_helpers.c
ecdab5bf616501a68e4559267acade37d1d8ad74
[libgit2.git] / tests / config / config_helpers.c
1 #include "clar_libgit2.h"
2 #include "config_helpers.h"
3 #include "repository.h"
4
5 void assert_config_entry_existence(
6 git_repository *repo,
7 const char *name,
8 bool is_supposed_to_exist)
9 {
10 git_config *config;
11 git_config_entry *entry = NULL;
12 int result;
13
14 cl_git_pass(git_repository_config__weakptr(&config, repo));
15
16 result = git_config_get_entry(&entry, config, name);
17 git_config_entry_free(entry);
18
19 if (is_supposed_to_exist)
20 cl_git_pass(result);
21 else
22 cl_assert_equal_i(GIT_ENOTFOUND, result);
23 }
24
25 void assert_config_entry_value(
26 git_repository *repo,
27 const char *name,
28 const char *expected_value)
29 {
30 git_config *config;
31 git_buf buf = GIT_BUF_INIT;
32
33 cl_git_pass(git_repository_config__weakptr(&config, repo));
34
35 cl_git_pass(git_config_get_string_buf(&buf, config, name));
36
37 cl_assert_equal_s(expected_value, buf.ptr);
38 git_buf_dispose(&buf);
39 }
40
41 static int count_config_entries_cb(
42 const git_config_entry *entry,
43 void *payload)
44 {
45 int *how_many = (int *)payload;
46
47 GIT_UNUSED(entry);
48
49 (*how_many)++;
50
51 return 0;
52 }
53
54 int count_config_entries_match(git_repository *repo, const char *pattern)
55 {
56 git_config *config;
57 int how_many = 0;
58
59 cl_git_pass(git_repository_config(&config, repo));
60
61 cl_assert_equal_i(0, git_config_foreach_match(
62 config, pattern, count_config_entries_cb, &how_many));
63
64 git_config_free(config);
65
66 return how_many;
67 }