]> git.proxmox.com Git - libgit2.git/blame - tests/config/include.c
rebase: correctly finish rebasing detached heads
[libgit2.git] / tests / config / include.c
CommitLineData
d8d25acb
CMN
1#include "clar_libgit2.h"
2#include "buffer.h"
3#include "fileops.h"
4
5void test_config_include__relative(void)
6{
7 git_config *cfg;
9a97f49e 8 git_buf buf = GIT_BUF_INIT;
d8d25acb
CMN
9
10 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
11
9a97f49e
CMN
12 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
13 cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
d8d25acb 14
9a97f49e 15 git_buf_free(&buf);
d8d25acb
CMN
16 git_config_free(cfg);
17}
18
19void test_config_include__absolute(void)
20{
21 git_config *cfg;
d8d25acb
CMN
22 git_buf buf = GIT_BUF_INIT;
23
24 cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
25
26 cl_git_mkfile("config-include-absolute", git_buf_cstr(&buf));
27 git_buf_free(&buf);
28 cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
29
9a97f49e
CMN
30 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
31 cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
d8d25acb 32
9a97f49e 33 git_buf_free(&buf);
d8d25acb
CMN
34 git_config_free(cfg);
35}
36
37void test_config_include__homedir(void)
38{
39 git_config *cfg;
9a97f49e 40 git_buf buf = GIT_BUF_INIT;
d8d25acb
CMN
41
42 cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
43 cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included");
44
45 cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
46
9a97f49e
CMN
47 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
48 cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
d8d25acb 49
9a97f49e 50 git_buf_free(&buf);
d8d25acb 51 git_config_free(cfg);
8487e237
RB
52
53 cl_sandbox_set_search_path_defaults();
d8d25acb 54}
a9fb7989 55
73fc5e01
CMN
56/* We need to pretend that the variables were defined where the file was included */
57void test_config_include__ordering(void)
58{
59 git_config *cfg;
9a97f49e 60 git_buf buf = GIT_BUF_INIT;
73fc5e01
CMN
61
62 cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya");
63 cl_git_mkfile("including",
64 "[foo \"bar\"]\nfrotz = hello\n"
65 "[include]\npath = included\n"
66 "[foo \"bar\"]\nbaz = huzzah\n");
67
68 cl_git_pass(git_config_open_ondisk(&cfg, "including"));
69
9a97f49e
CMN
70 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
71 cl_assert_equal_s("hiya", git_buf_cstr(&buf));
72 git_buf_clear(&buf);
73 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
74 cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
73fc5e01 75
9a97f49e 76 git_buf_free(&buf);
73fc5e01
CMN
77 git_config_free(cfg);
78}
53ea0513
CMN
79
80/* We need to pretend that the variables were defined where the file was included */
81void test_config_include__depth(void)
82{
83 git_config *cfg;
84
85 cl_git_mkfile("a", "[include]\npath = b");
86 cl_git_mkfile("b", "[include]\npath = a");
87
88 cl_git_fail(git_config_open_ondisk(&cfg, "a"));
89
34100846
ET
90 p_unlink("a");
91 p_unlink("b");
53ea0513 92}
727ae380
JF
93
94void test_config_include__missing(void)
95{
96 git_config *cfg;
9a97f49e 97 git_buf buf = GIT_BUF_INIT;
727ae380 98
ebc13b2b 99 cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
727ae380 100
ebc13b2b
JF
101 giterr_clear();
102 cl_git_pass(git_config_open_ondisk(&cfg, "including"));
103 cl_assert(giterr_last() == NULL);
9a97f49e
CMN
104 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
105 cl_assert_equal_s("baz", git_buf_cstr(&buf));
727ae380 106
9a97f49e 107 git_buf_free(&buf);
727ae380 108 git_config_free(cfg);
727ae380 109}
3ea78f24
YK
110
111#define replicate10(s) s s s s s s s s s s
112void test_config_include__depth2(void)
113{
114 git_config *cfg;
9a97f49e 115 git_buf buf = GIT_BUF_INIT;
3ea78f24
YK
116 const char *content = "[include]\n" replicate10(replicate10("path=bottom\n"));
117
118 cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz");
119 cl_git_mkfile("middle", content);
120 cl_git_mkfile("bottom", "[foo]\nbar2 = baz2");
121
122 cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
123
9a97f49e
CMN
124 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
125 cl_assert_equal_s("baz", git_buf_cstr(&buf));
3ea78f24 126
9a97f49e
CMN
127 git_buf_clear(&buf);
128 cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
129 cl_assert_equal_s("baz2", git_buf_cstr(&buf));
3ea78f24 130
fe21d708 131 git_buf_free(&buf);
3ea78f24
YK
132 git_config_free(cfg);
133}