]> git.proxmox.com Git - libgit2.git/blob - tests/config/config_helpers.c
Merge remote-tracking branch 'origin/development' into fix-git-status-list-new-unread...
[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 const char *out;
12 int result;
13
14 cl_git_pass(git_repository_config__weakptr(&config, repo));
15
16 result = git_config_get_string(&out, config, name);
17
18 if (is_supposed_to_exist)
19 cl_git_pass(result);
20 else
21 cl_assert_equal_i(GIT_ENOTFOUND, result);
22 }
23
24 void assert_config_entry_value(
25 git_repository *repo,
26 const char *name,
27 const char *expected_value)
28 {
29 git_config *config;
30 const char *out;
31
32 cl_git_pass(git_repository_config__weakptr(&config, repo));
33
34 cl_git_pass(git_config_get_string(&out, config, name));
35
36 cl_assert_equal_s(expected_value, out);
37 }
38
39 static int count_config_entries_cb(
40 const git_config_entry *entry,
41 void *payload)
42 {
43 int *how_many = (int *)payload;
44
45 GIT_UNUSED(entry);
46
47 (*how_many)++;
48
49 return 0;
50 }
51
52 int count_config_entries_match(git_repository *repo, const char *pattern)
53 {
54 git_config *config;
55 int how_many = 0;
56
57 cl_git_pass(git_repository_config(&config, repo));
58
59 cl_assert_equal_i(0, git_config_foreach_match(
60 config, pattern, count_config_entries_cb, &how_many));
61
62 git_config_free(config);
63
64 return how_many;
65 }