Merge pull request #5034 from pks-t/pks/symlinked-user-config Tests for symlinked user config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
diff --git a/tests/config/global.c b/tests/config/global.c
index 9446d8d..647a110 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 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