Skip to content

Commit 25c085e

Browse files
committed
tests: repo: verify that we can open repos with symlinked global config
We've got reports that users are unable to open repos when their global configuration ("~/.gitconfig") is a symlink. Add a test to verify that we are in fact able to do so as expected.
1 parent fa4505e commit 25c085e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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)