Commit 25c085e6e0be04bf044ec1fb1d117af82b401ebc

Patrick Steinhardt 2019-03-29T11:41:42

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.

diff --git a/tests/repo/open.c b/tests/repo/open.c
index 06ec71b..5c08a38 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -118,6 +118,36 @@ void test_repo_open__gitlinked(void)
 	git_repository_free(repo2);
 }
 
+void test_repo_open__with_symlinked_config(void)
+{
+#ifndef GIT_WIN32
+	git_buf path = GIT_BUF_INIT;
+	git_repository *repo;
+	git_config *cfg;
+	int32_t value;
+
+	cl_git_sandbox_init("empty_standard_repo");
+
+	/* Setup .gitconfig as symlink */
+	cl_git_pass(git_futils_mkdir_r("home", 0777));
+	cl_git_mkfile("home/.gitconfig.linked", "[global]\ntest = 4567\n");
+	cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
+	cl_git_pass(git_path_prettify(&path, "home", NULL));
+	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
+
+	cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
+	cl_git_pass(git_config_open_default(&cfg));
+	cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
+	cl_assert_equal_i(4567, value);
+
+	git_config_free(cfg);
+	git_repository_free(repo);
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+	cl_sandbox_set_search_path_defaults();
+	git_buf_dispose(&path);
+#endif
+}
+
 void test_repo_open__from_git_new_workdir(void)
 {
 #ifndef GIT_WIN32