summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-03 12:58:23 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-04 09:05:16 +0100
commit389f9b10e6e71339fe28145098a37975c49a472d (patch)
tree641c303113e226c50995bc0fe588b11550af5c89 /tests
parent24b9c4b63374e850d165ae5f7055db6e47ff3051 (diff)
downloadlibgit2-389f9b10e6e71339fe28145098a37975c49a472d.tar.gz
repo: honor GIT_CONFIG_* environment variables
When the repository is opened with `GIT_REPOSITORY_OPEN_FROM_ENV`, honor the `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM` and `GIT_CONFIG_NOSYSTEM` environment variables.
Diffstat (limited to 'tests')
-rw-r--r--tests/libgit2/repo/env.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/libgit2/repo/env.c b/tests/libgit2/repo/env.c
index 4a61581bd..0e6cc59d5 100644
--- a/tests/libgit2/repo/env.c
+++ b/tests/libgit2/repo/env.c
@@ -32,6 +32,8 @@ void test_repo_env__cleanup(void)
git_futils_rmdir_r("peeled.git", NULL, GIT_RMDIR_REMOVE_FILES);
cl_fixture_cleanup("test_workdir");
+ cl_fixture_cleanup("test_global_conf");
+ cl_fixture_cleanup("test_system_conf");
clear_git_env();
}
@@ -315,3 +317,53 @@ void test_repo_env__commondir(void)
git_repository_free(repo);
cl_setenv("GIT_COMMON_DIR", NULL);
}
+
+void test_repo_env__config(void)
+{
+ git_repository *repo;
+ git_config *config;
+ const char *system_path, *global_path;
+ int s, g;
+
+ cl_fixture_sandbox("attr");
+ cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
+
+ cl_git_rewritefile("test_system_conf", "[tttest]\n\tsys = true\n");
+ cl_git_rewritefile("test_global_conf", "[tttest]\n\tglb = true\n");
+
+ system_path = cl_git_sandbox_path(0, "test_system_conf", NULL);
+ cl_setenv("GIT_CONFIG_SYSTEM", system_path);
+
+ global_path = cl_git_sandbox_path(0, "test_global_conf", NULL);
+ cl_setenv("GIT_CONFIG_GLOBAL", global_path);
+
+ /* Ensure we can override the system and global files */
+
+ cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
+ cl_git_pass(git_repository_config(&config, repo));
+
+ cl_git_pass(git_config_get_bool(&s, config, "tttest.sys"));
+ cl_assert_equal_i(1, s);
+ cl_git_pass(git_config_get_bool(&g, config, "tttest.glb"));
+ cl_assert_equal_i(1, g);
+
+ git_config_free(config);
+ git_repository_free(repo);
+
+ /* Further ensure we can ignore the system file. */
+ cl_setenv("GIT_CONFIG_NOSYSTEM", "TrUe");
+
+ cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
+ cl_git_pass(git_repository_config(&config, repo));
+
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_get_bool(&s, config, "tttest.sys"));
+ cl_git_pass(git_config_get_bool(&g, config, "tttest.glb"));
+ cl_assert_equal_i(1, g);
+
+ git_config_free(config);
+ git_repository_free(repo);
+
+ cl_setenv("GIT_CONFIG_NOSYSTEM", NULL);
+ cl_setenv("GIT_CONFIG_SYSTEM", NULL);
+ cl_setenv("GIT_CONFIG_GLOBAL", NULL);
+}