Skip to content

Commit 80db204

Browse files
authored
Merge pull request libgit2#5034 from pks-t/pks/symlinked-user-config
Tests for symlinked user config
2 parents 6bcb735 + 8cf3fd9 commit 80db204

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/config/global.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,54 @@ void test_config_global__initialize(void)
2727
void test_config_global__cleanup(void)
2828
{
2929
cl_sandbox_set_search_path_defaults();
30+
cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
31+
cl_git_pass(git_futils_rmdir_r("xdg", NULL, GIT_RMDIR_REMOVE_FILES));
32+
cl_git_pass(git_futils_rmdir_r("etc", NULL, GIT_RMDIR_REMOVE_FILES));
3033
}
3134

3235
void test_config_global__open_global(void)
3336
{
3437
git_config *cfg, *global, *selected, *dummy;
38+
int32_t value;
39+
40+
cl_git_mkfile("home/.gitconfig", "[global]\n test = 4567\n");
3541

3642
cl_git_pass(git_config_open_default(&cfg));
43+
cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
44+
cl_assert_equal_i(4567, value);
45+
3746
cl_git_pass(git_config_open_level(&global, cfg, GIT_CONFIG_LEVEL_GLOBAL));
47+
cl_git_pass(git_config_get_int32(&value, global, "global.test"));
48+
cl_assert_equal_i(4567, value);
49+
3850
cl_git_fail(git_config_open_level(&dummy, cfg, GIT_CONFIG_LEVEL_XDG));
51+
3952
cl_git_pass(git_config_open_global(&selected, cfg));
53+
cl_git_pass(git_config_get_int32(&value, selected, "global.test"));
54+
cl_assert_equal_i(4567, value);
4055

4156
git_config_free(selected);
4257
git_config_free(global);
4358
git_config_free(cfg);
4459
}
4560

61+
void test_config_global__open_symlinked_global(void)
62+
{
63+
#ifndef GIT_WIN32
64+
git_config *cfg;
65+
int32_t value;
66+
67+
cl_git_mkfile("home/.gitconfig.linked", "[global]\n test = 4567\n");
68+
cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
69+
70+
cl_git_pass(git_config_open_default(&cfg));
71+
cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
72+
cl_assert_equal_i(4567, value);
73+
74+
git_config_free(cfg);
75+
#endif
76+
}
77+
4678
void test_config_global__open_xdg(void)
4779
{
4880
git_config *cfg, *xdg, *selected;

tests/repo/open.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,36 @@ void test_repo_open__gitlinked(void)
118118
git_repository_free(repo2);
119119
}
120120

121+
void test_repo_open__with_symlinked_config(void)
122+
{
123+
#ifndef GIT_WIN32
124+
git_buf path = GIT_BUF_INIT;
125+
git_repository *repo;
126+
git_config *cfg;
127+
int32_t value;
128+
129+
cl_git_sandbox_init("empty_standard_repo");
130+
131+
/* Setup .gitconfig as symlink */
132+
cl_git_pass(git_futils_mkdir_r("home", 0777));
133+
cl_git_mkfile("home/.gitconfig.linked", "[global]\ntest = 4567\n");
134+
cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
135+
cl_git_pass(git_path_prettify(&path, "home", NULL));
136+
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
137+
138+
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
139+
cl_git_pass(git_config_open_default(&cfg));
140+
cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
141+
cl_assert_equal_i(4567, value);
142+
143+
git_config_free(cfg);
144+
git_repository_free(repo);
145+
cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
146+
cl_sandbox_set_search_path_defaults();
147+
git_buf_dispose(&path);
148+
#endif
149+
}
150+
121151
void test_repo_open__from_git_new_workdir(void)
122152
{
123153
#ifndef GIT_WIN32

0 commit comments

Comments
 (0)