|
1 | 1 | #include "clar_libgit2.h" |
| 2 | +#include "buffer.h" |
| 3 | +#include "path.h" |
2 | 4 |
|
3 | 5 | void test_config_read__simple_read(void) |
4 | 6 | { |
@@ -567,3 +569,47 @@ void test_config_read__override_variable(void) |
567 | 569 |
|
568 | 570 | git_config_free(cfg); |
569 | 571 | } |
| 572 | + |
| 573 | +void test_config_read__path(void) |
| 574 | +{ |
| 575 | + git_config *cfg; |
| 576 | + git_buf path = GIT_BUF_INIT; |
| 577 | + git_buf old_path = GIT_BUF_INIT; |
| 578 | + git_buf home_path = GIT_BUF_INIT; |
| 579 | + git_buf expected_path = GIT_BUF_INIT; |
| 580 | + |
| 581 | + cl_git_pass(p_mkdir("fakehome", 0777)); |
| 582 | + cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL)); |
| 583 | + cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path)); |
| 584 | + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr)); |
| 585 | + cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile"); |
| 586 | + cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL)); |
| 587 | + |
| 588 | + cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); |
| 589 | + cl_git_pass(git_config_get_path(&path, cfg, "some.path")); |
| 590 | + cl_assert_equal_s(expected_path.ptr, path.ptr); |
| 591 | + git_buf_free(&path); |
| 592 | + |
| 593 | + cl_git_mkfile("./testconfig", "[some]\n path = ~/"); |
| 594 | + cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL)); |
| 595 | + |
| 596 | + cl_git_pass(git_config_get_path(&path, cfg, "some.path")); |
| 597 | + cl_assert_equal_s(expected_path.ptr, path.ptr); |
| 598 | + git_buf_free(&path); |
| 599 | + |
| 600 | + cl_git_mkfile("./testconfig", "[some]\n path = ~"); |
| 601 | + cl_git_pass(git_buf_sets(&expected_path, home_path.ptr)); |
| 602 | + |
| 603 | + cl_git_pass(git_config_get_path(&path, cfg, "some.path")); |
| 604 | + cl_assert_equal_s(expected_path.ptr, path.ptr); |
| 605 | + git_buf_free(&path); |
| 606 | + |
| 607 | + cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo"); |
| 608 | + cl_git_fail(git_config_get_path(&path, cfg, "some.path")); |
| 609 | + |
| 610 | + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr)); |
| 611 | + git_buf_free(&old_path); |
| 612 | + git_buf_free(&home_path); |
| 613 | + git_buf_free(&expected_path); |
| 614 | + git_config_free(cfg); |
| 615 | +} |
0 commit comments