summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-04-04 14:16:44 -0700
committerGitHub <noreply@github.com>2019-04-04 14:16:44 -0700
commit80db20430ec103cc8b3ca1734770e50c84c626ab (patch)
tree382e1844378f0285934fd07f6ad6e8ef2b319c1a
parent6bcb7357eccdab4de948af55836ce25f76dd7270 (diff)
parent8cf3fd93a17fe8e69bc541e3696a946be409291c (diff)
downloadlibgit2-80db20430ec103cc8b3ca1734770e50c84c626ab.tar.gz
Merge pull request #5034 from pks-t/pks/symlinked-user-config
Tests for symlinked user config
-rw-r--r--tests/config/global.c32
-rw-r--r--tests/repo/open.c30
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/config/global.c b/tests/config/global.c
index 9446d8de9..647a110e3 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -27,22 +27,54 @@ void test_config_global__initialize(void)
void test_config_global__cleanup(void)
{
cl_sandbox_set_search_path_defaults();
+ cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_futils_rmdir_r("xdg", NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_git_pass(git_futils_rmdir_r("etc", NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_config_global__open_global(void)
{
git_config *cfg, *global, *selected, *dummy;
+ int32_t value;
+
+ cl_git_mkfile("home/.gitconfig", "[global]\n test = 4567\n");
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);
+
cl_git_pass(git_config_open_level(&global, cfg, GIT_CONFIG_LEVEL_GLOBAL));
+ cl_git_pass(git_config_get_int32(&value, global, "global.test"));
+ cl_assert_equal_i(4567, value);
+
cl_git_fail(git_config_open_level(&dummy, cfg, GIT_CONFIG_LEVEL_XDG));
+
cl_git_pass(git_config_open_global(&selected, cfg));
+ cl_git_pass(git_config_get_int32(&value, selected, "global.test"));
+ cl_assert_equal_i(4567, value);
git_config_free(selected);
git_config_free(global);
git_config_free(cfg);
}
+void test_config_global__open_symlinked_global(void)
+{
+#ifndef GIT_WIN32
+ git_config *cfg;
+ int32_t value;
+
+ cl_git_mkfile("home/.gitconfig.linked", "[global]\n test = 4567\n");
+ cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
+
+ 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);
+#endif
+}
+
void test_config_global__open_xdg(void)
{
git_config *cfg, *xdg, *selected;
diff --git a/tests/repo/open.c b/tests/repo/open.c
index 06ec71bfd..5c08a388c 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