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