]> git.proxmox.com Git - libgit2.git/blob - tests/config/config_helpers.c
Merge pull request #3010 from ethomson/checkout_invalid_path_err
[libgit2.git] / tests / config / config_helpers.c
1 #include "clar_libgit2.h"
2 #include "config_helpers.h"
3 #include "repository.h"
4 #include "buffer.h"
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;
12 git_config_entry *entry = NULL;
13 int result;
14
15 cl_git_pass(git_repository_config__weakptr(&config, repo));
16
17 result = git_config_get_entry(&entry, config, name);
18 git_config_entry_free(entry);
19
20 if (is_supposed_to_exist)
21 cl_git_pass(result);
22 else
23 cl_assert_equal_i(GIT_ENOTFOUND, result);
24 }
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;
32 git_buf buf = GIT_BUF_INIT;
33
34 cl_git_pass(git_repository_config__weakptr(&config, repo));
35
36 cl_git_pass(git_config_get_string_buf(&buf, config, name));
37
38 cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
39 git_buf_free(&buf);
40 }
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 }