]> git.proxmox.com Git - libgit2.git/blob - tests/config/read.c
config_file: comment char can be invalid escape
[libgit2.git] / tests / config / read.c
1 #include "clar_libgit2.h"
2 #include "buffer.h"
3 #include "path.h"
4
5 static git_buf buf = GIT_BUF_INIT;
6
7 void test_config_read__cleanup(void)
8 {
9 git_buf_free(&buf);
10 }
11
12 void test_config_read__simple_read(void)
13 {
14 git_config *cfg;
15 int32_t i;
16
17 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config0")));
18
19 cl_git_pass(git_config_get_int32(&i, cfg, "core.repositoryformatversion"));
20 cl_assert(i == 0);
21 cl_git_pass(git_config_get_bool(&i, cfg, "core.filemode"));
22 cl_assert(i == 1);
23 cl_git_pass(git_config_get_bool(&i, cfg, "core.bare"));
24 cl_assert(i == 0);
25 cl_git_pass(git_config_get_bool(&i, cfg, "core.logallrefupdates"));
26 cl_assert(i == 1);
27
28 git_config_free(cfg);
29 }
30
31 void test_config_read__case_sensitive(void)
32 {
33 git_config *cfg;
34 int i;
35
36 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
37
38 cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
39 cl_assert_equal_s("true", git_buf_cstr(&buf));
40 git_buf_clear(&buf);
41
42 cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
43 cl_assert_equal_s("yes", git_buf_cstr(&buf));
44
45 cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
46 cl_assert(i == 1);
47 cl_git_pass(git_config_get_bool(&i, cfg, "this.That.other"));
48 cl_assert(i == 1);
49
50 /* This one doesn't exist */
51 cl_must_fail(git_config_get_bool(&i, cfg, "this.thaT.other"));
52
53 git_config_free(cfg);
54 }
55
56 /*
57 * If \ is the last non-space character on the line, we read the next
58 * one, separating each line with SP.
59 */
60 void test_config_read__multiline_value(void)
61 {
62 git_config *cfg;
63
64 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
65
66 cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
67 cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
68
69 git_config_free(cfg);
70 }
71
72 static void clean_test_config(void *unused)
73 {
74 GIT_UNUSED(unused);
75 cl_fixture_cleanup("./testconfig");
76 }
77
78 void test_config_read__multiline_value_and_eof(void)
79 {
80 git_config *cfg;
81
82 cl_set_cleanup(&clean_test_config, NULL);
83 cl_git_mkfile("./testconfig", "[header]\n key1 = foo\\\n");
84 cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
85
86 cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
87 cl_assert_equal_s("foo", git_buf_cstr(&buf));
88
89 git_config_free(cfg);
90 }
91
92 void test_config_read__multiline_eof(void)
93 {
94 git_config *cfg;
95
96 cl_set_cleanup(&clean_test_config, NULL);
97 cl_git_mkfile("./testconfig", "[header]\n key1 = \\\n");
98 cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
99
100 cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
101 cl_assert_equal_s("", git_buf_cstr(&buf));
102
103 git_config_free(cfg);
104 }
105
106 /*
107 * This kind of subsection declaration is case-insensitive
108 */
109 void test_config_read__subsection_header(void)
110 {
111 git_config *cfg;
112
113 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
114
115 cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
116 cl_assert_equal_s("hello", git_buf_cstr(&buf));
117
118 /* The subsection is transformed to lower-case */
119 cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
120
121 git_config_free(cfg);
122 }
123
124 void test_config_read__lone_variable(void)
125 {
126 git_config *cfg;
127 int i;
128
129 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4")));
130
131 cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
132
133 cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
134 cl_assert_equal_s("", git_buf_cstr(&buf));
135 git_buf_clear(&buf);
136
137 cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
138 cl_assert(i == 1);
139
140 cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
141 cl_assert_equal_s("", git_buf_cstr(&buf));
142
143 cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
144 cl_assert(i == 0);
145
146 git_config_free(cfg);
147 }
148
149 void test_config_read__number_suffixes(void)
150 {
151 git_config *cfg;
152 int64_t i;
153
154 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config5")));
155
156 cl_git_pass(git_config_get_int64(&i, cfg, "number.simple"));
157 cl_assert(i == 1);
158
159 cl_git_pass(git_config_get_int64(&i, cfg, "number.k"));
160 cl_assert(i == 1 * 1024);
161
162 cl_git_pass(git_config_get_int64(&i, cfg, "number.kk"));
163 cl_assert(i == 1 * 1024);
164
165 cl_git_pass(git_config_get_int64(&i, cfg, "number.m"));
166 cl_assert(i == 1 * 1024 * 1024);
167
168 cl_git_pass(git_config_get_int64(&i, cfg, "number.mm"));
169 cl_assert(i == 1 * 1024 * 1024);
170
171 cl_git_pass(git_config_get_int64(&i, cfg, "number.g"));
172 cl_assert(i == 1 * 1024 * 1024 * 1024);
173
174 cl_git_pass(git_config_get_int64(&i, cfg, "number.gg"));
175 cl_assert(i == 1 * 1024 * 1024 * 1024);
176
177 git_config_free(cfg);
178 }
179
180 void test_config_read__blank_lines(void)
181 {
182 git_config *cfg;
183 int i;
184
185 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config6")));
186
187 cl_git_pass(git_config_get_bool(&i, cfg, "valid.subsection.something"));
188 cl_assert(i == 1);
189
190 cl_git_pass(git_config_get_bool(&i, cfg, "something.else.something"));
191 cl_assert(i == 0);
192
193 git_config_free(cfg);
194 }
195
196 void test_config_read__invalid_ext_headers(void)
197 {
198 git_config *cfg;
199 cl_must_fail(git_config_open_ondisk(&cfg, cl_fixture("config/config7")));
200 }
201
202 void test_config_read__empty_files(void)
203 {
204 git_config *cfg;
205 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config8")));
206 git_config_free(cfg);
207 }
208
209 void test_config_read__symbol_headers(void)
210 {
211 git_config *cfg;
212 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config20")));
213 git_config_free(cfg);
214 }
215
216 void test_config_read__header_in_last_line(void)
217 {
218 git_config *cfg;
219
220 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config10")));
221 git_config_free(cfg);
222 }
223
224 void test_config_read__prefixes(void)
225 {
226 git_config *cfg;
227
228 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
229 cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
230 cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
231 git_buf_clear(&buf);
232
233 cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
234 cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
235
236 git_config_free(cfg);
237 }
238
239 void test_config_read__escaping_quotes(void)
240 {
241 git_config *cfg;
242
243 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
244 cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
245 cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
246
247 git_config_free(cfg);
248 }
249
250 void test_config_read__invalid_escape_sequence(void)
251 {
252 git_config *cfg;
253
254 cl_set_cleanup(&clean_test_config, NULL);
255 cl_git_mkfile("./testconfig", "[header]\n key1 = \\\\\\;\n key2 = value2\n");
256 cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
257
258 git_config_free(cfg);
259 }
260
261 static int count_cfg_entries_and_compare_levels(
262 const git_config_entry *entry, void *payload)
263 {
264 int *count = payload;
265
266 if (!strcmp(entry->value, "7") || !strcmp(entry->value, "17"))
267 cl_assert(entry->level == GIT_CONFIG_LEVEL_GLOBAL);
268 else
269 cl_assert(entry->level == GIT_CONFIG_LEVEL_SYSTEM);
270
271 (*count)++;
272 return 0;
273 }
274
275 static int cfg_callback_countdown(const git_config_entry *entry, void *payload)
276 {
277 int *count = payload;
278 GIT_UNUSED(entry);
279 (*count)--;
280 if (*count == 0)
281 return -100;
282 return 0;
283 }
284
285 void test_config_read__foreach(void)
286 {
287 git_config *cfg;
288 int count, ret;
289
290 cl_git_pass(git_config_new(&cfg));
291 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
292 GIT_CONFIG_LEVEL_SYSTEM, 0));
293 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
294 GIT_CONFIG_LEVEL_GLOBAL, 0));
295
296 count = 0;
297 cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
298 cl_assert_equal_i(7, count);
299
300 count = 3;
301 cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count));
302 cl_assert_equal_i(-100, ret);
303
304 git_config_free(cfg);
305 }
306
307 void test_config_read__iterator(void)
308 {
309 git_config *cfg;
310 git_config_iterator *iter;
311 git_config_entry *entry;
312 int count, ret;
313
314 cl_git_pass(git_config_new(&cfg));
315 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
316 GIT_CONFIG_LEVEL_SYSTEM, 0));
317 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
318 GIT_CONFIG_LEVEL_GLOBAL, 0));
319
320 count = 0;
321 cl_git_pass(git_config_iterator_new(&iter, cfg));
322
323 while ((ret = git_config_next(&entry, iter)) == 0) {
324 count++;
325 }
326
327 git_config_iterator_free(iter);
328 cl_assert_equal_i(GIT_ITEROVER, ret);
329 cl_assert_equal_i(7, count);
330
331 count = 3;
332 cl_git_pass(git_config_iterator_new(&iter, cfg));
333
334 git_config_iterator_free(iter);
335 git_config_free(cfg);
336 }
337
338 static int count_cfg_entries(const git_config_entry *entry, void *payload)
339 {
340 int *count = payload;
341 GIT_UNUSED(entry);
342 (*count)++;
343 return 0;
344 }
345
346 void test_config_read__foreach_match(void)
347 {
348 git_config *cfg;
349 int count;
350
351 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
352
353 count = 0;
354 cl_git_pass(
355 git_config_foreach_match(cfg, "core.*", count_cfg_entries, &count));
356 cl_assert_equal_i(3, count);
357
358 count = 0;
359 cl_git_pass(
360 git_config_foreach_match(cfg, "remote\\.ab.*", count_cfg_entries, &count));
361 cl_assert_equal_i(2, count);
362
363 count = 0;
364 cl_git_pass(
365 git_config_foreach_match(cfg, ".*url$", count_cfg_entries, &count));
366 cl_assert_equal_i(2, count);
367
368 count = 0;
369 cl_git_pass(
370 git_config_foreach_match(cfg, ".*dummy.*", count_cfg_entries, &count));
371 cl_assert_equal_i(2, count);
372
373 count = 0;
374 cl_git_pass(
375 git_config_foreach_match(cfg, ".*nomatch.*", count_cfg_entries, &count));
376 cl_assert_equal_i(0, count);
377
378 git_config_free(cfg);
379 }
380
381 static void check_glob_iter(git_config *cfg, const char *regexp, int expected)
382 {
383 git_config_iterator *iter;
384 git_config_entry *entry;
385 int count, error;
386
387 cl_git_pass(git_config_iterator_glob_new(&iter, cfg, regexp));
388
389 count = 0;
390 while ((error = git_config_next(&entry, iter)) == 0)
391 count++;
392
393 cl_assert_equal_i(GIT_ITEROVER, error);
394 cl_assert_equal_i(expected, count);
395 git_config_iterator_free(iter);
396 }
397
398 void test_config_read__iterator_invalid_glob(void)
399 {
400 git_config *cfg;
401 git_config_iterator *iter;
402
403 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
404
405 cl_git_fail(git_config_iterator_glob_new(&iter, cfg, "*"));
406
407 git_config_free(cfg);
408 }
409
410 void test_config_read__iterator_glob(void)
411 {
412 git_config *cfg;
413
414 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
415
416 check_glob_iter(cfg, "core.*", 3);
417 check_glob_iter(cfg, "remote\\.ab.*", 2);
418 check_glob_iter(cfg, ".*url$", 2);
419 check_glob_iter(cfg, ".*dummy.*", 2);
420 check_glob_iter(cfg, ".*nomatch.*", 0);
421
422 git_config_free(cfg);
423 }
424
425 void test_config_read__whitespace_not_required_around_assignment(void)
426 {
427 git_config *cfg;
428
429 cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
430
431 cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
432 cl_assert_equal_s("c", git_buf_cstr(&buf));
433 git_buf_clear(&buf);
434
435 cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
436 cl_assert_equal_s("f", git_buf_cstr(&buf));
437
438 git_config_free(cfg);
439 }
440
441 void test_config_read__read_git_config_entry(void)
442 {
443 git_config *cfg;
444 git_config_entry *entry;
445
446 cl_git_pass(git_config_new(&cfg));
447 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
448 GIT_CONFIG_LEVEL_SYSTEM, 0));
449
450 cl_git_pass(git_config_get_entry(&entry, cfg, "core.dummy2"));
451 cl_assert_equal_s("core.dummy2", entry->name);
452 cl_assert_equal_s("42", entry->value);
453 cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level);
454
455 git_config_entry_free(entry);
456 git_config_free(cfg);
457 }
458
459 /*
460 * At the beginning of the test:
461 * - config9 has: core.dummy2=42
462 * - config15 has: core.dummy2=7
463 * - config16 has: core.dummy2=28
464 */
465 void test_config_read__local_config_overrides_global_config_overrides_system_config(void)
466 {
467 git_config *cfg;
468 int32_t i;
469
470 cl_git_pass(git_config_new(&cfg));
471 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
472 GIT_CONFIG_LEVEL_SYSTEM, 0));
473 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
474 GIT_CONFIG_LEVEL_GLOBAL, 0));
475 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
476 GIT_CONFIG_LEVEL_LOCAL, 0));
477
478 cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
479 cl_assert_equal_i(28, i);
480
481 git_config_free(cfg);
482
483 cl_git_pass(git_config_new(&cfg));
484 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
485 GIT_CONFIG_LEVEL_SYSTEM, 0));
486 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
487 GIT_CONFIG_LEVEL_GLOBAL, 0));
488
489 cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
490 cl_assert_equal_i(7, i);
491
492 git_config_free(cfg);
493 }
494
495 /*
496 * At the beginning of the test:
497 * - config9 has: core.global does not exist
498 * - config15 has: core.global=17
499 * - config16 has: core.global=29
500 *
501 * And also:
502 * - config9 has: core.system does not exist
503 * - config15 has: core.system does not exist
504 * - config16 has: core.system=11
505 */
506 void test_config_read__fallback_from_local_to_global_and_from_global_to_system(void)
507 {
508 git_config *cfg;
509 int32_t i;
510
511 cl_git_pass(git_config_new(&cfg));
512 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
513 GIT_CONFIG_LEVEL_SYSTEM, 0));
514 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
515 GIT_CONFIG_LEVEL_GLOBAL, 0));
516 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
517 GIT_CONFIG_LEVEL_LOCAL, 0));
518
519 cl_git_pass(git_config_get_int32(&i, cfg, "core.global"));
520 cl_assert_equal_i(17, i);
521 cl_git_pass(git_config_get_int32(&i, cfg, "core.system"));
522 cl_assert_equal_i(11, i);
523
524 git_config_free(cfg);
525 }
526
527 /*
528 * At the beginning of the test, config18 has:
529 * int32global = 28
530 * int64global = 9223372036854775803
531 * boolglobal = true
532 * stringglobal = I'm a global config value!
533 *
534 * And config19 has:
535 * int32global = -1
536 * int64global = -2
537 * boolglobal = false
538 * stringglobal = don't find me!
539 *
540 */
541 void test_config_read__simple_read_from_specific_level(void)
542 {
543 git_config *cfg, *cfg_specific;
544 int i;
545 int64_t l, expected = +9223372036854775803;
546
547 cl_git_pass(git_config_new(&cfg));
548 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
549 GIT_CONFIG_LEVEL_GLOBAL, 0));
550 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
551 GIT_CONFIG_LEVEL_SYSTEM, 0));
552
553 cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
554
555 cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global"));
556 cl_assert_equal_i(28, i);
557 cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global"));
558 cl_assert(l == expected);
559 cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
560 cl_assert_equal_b(true, i);
561 cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
562 cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
563
564 git_config_free(cfg_specific);
565 git_config_free(cfg);
566 }
567
568 void test_config_read__can_load_and_parse_an_empty_config_file(void)
569 {
570 git_config *cfg;
571 int i;
572
573 cl_set_cleanup(&clean_test_config, NULL);
574 cl_git_mkfile("./testconfig", "");
575 cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
576 cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither"));
577
578 git_config_free(cfg);
579 }
580
581 void test_config_read__corrupt_header(void)
582 {
583 git_config *cfg;
584
585 cl_set_cleanup(&clean_test_config, NULL);
586 cl_git_mkfile("./testconfig", "[sneaky ] \"quoted closing quote mark\\\"");
587 cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
588
589 git_config_free(cfg);
590 }
591
592 void test_config_read__corrupt_header2(void)
593 {
594 git_config *cfg;
595
596 cl_set_cleanup(&clean_test_config, NULL);
597 cl_git_mkfile("./testconfig", "[unclosed \"bracket\"\n lib = git2\n");
598 cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
599
600 git_config_free(cfg);
601 }
602
603 void test_config_read__corrupt_header3(void)
604 {
605 git_config *cfg;
606
607 cl_set_cleanup(&clean_test_config, NULL);
608 cl_git_mkfile("./testconfig", "[unclosed \"slash\\\"]\n lib = git2\n");
609 cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
610
611 git_config_free(cfg);
612 }
613
614 void test_config_read__override_variable(void)
615 {
616 git_config *cfg;
617
618 cl_set_cleanup(&clean_test_config, NULL);
619 cl_git_mkfile("./testconfig", "[some] var = one\nvar = two");
620 cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
621
622 cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
623 cl_assert_equal_s("two", git_buf_cstr(&buf));
624
625 git_config_free(cfg);
626 }
627
628 void test_config_read__path(void)
629 {
630 git_config *cfg;
631 git_buf path = GIT_BUF_INIT;
632 git_buf old_path = GIT_BUF_INIT;
633 git_buf home_path = GIT_BUF_INIT;
634 git_buf expected_path = GIT_BUF_INIT;
635
636 cl_git_pass(p_mkdir("fakehome", 0777));
637 cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL));
638 cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path));
639 cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr));
640 cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile");
641 cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
642
643 cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
644 cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
645 cl_assert_equal_s(expected_path.ptr, path.ptr);
646 git_buf_free(&path);
647
648 cl_git_mkfile("./testconfig", "[some]\n path = ~/");
649 cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL));
650
651 cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
652 cl_assert_equal_s(expected_path.ptr, path.ptr);
653 git_buf_free(&path);
654
655 cl_git_mkfile("./testconfig", "[some]\n path = ~");
656 cl_git_pass(git_buf_sets(&expected_path, home_path.ptr));
657
658 cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
659 cl_assert_equal_s(expected_path.ptr, path.ptr);
660 git_buf_free(&path);
661
662 cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo");
663 cl_git_fail(git_config_get_path(&path, cfg, "some.path"));
664
665 cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr));
666 git_buf_free(&old_path);
667 git_buf_free(&home_path);
668 git_buf_free(&expected_path);
669 git_config_free(cfg);
670 }