]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/config/config_helpers.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / config / config_helpers.c
CommitLineData
0b98a8a4 1#include "clar_libgit2.h"
2#include "config_helpers.h"
3#include "repository.h"
4
5void assert_config_entry_existence(
6 git_repository *repo,
7 const char *name,
8 bool is_supposed_to_exist)
9{
10 git_config *config;
9a97f49e 11 git_config_entry *entry = NULL;
0b98a8a4 12 int result;
13
14 cl_git_pass(git_repository_config__weakptr(&config, repo));
e579e0f7 15
9a97f49e
CMN
16 result = git_config_get_entry(&entry, config, name);
17 git_config_entry_free(entry);
0b98a8a4 18
19 if (is_supposed_to_exist)
20 cl_git_pass(result);
21 else
22 cl_assert_equal_i(GIT_ENOTFOUND, result);
23}
fcccf304 24
25void assert_config_entry_value(
26 git_repository *repo,
27 const char *name,
28 const char *expected_value)
29{
30 git_config *config;
9a97f49e 31 git_buf buf = GIT_BUF_INIT;
fcccf304 32
33 cl_git_pass(git_repository_config__weakptr(&config, repo));
34
9a97f49e 35 cl_git_pass(git_config_get_string_buf(&buf, config, name));
fcccf304 36
e579e0f7 37 cl_assert_equal_s(expected_value, buf.ptr);
ac3d33df 38 git_buf_dispose(&buf);
fcccf304 39}
48ebea66 40
41static 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
54int 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}