Commit ff67b5e1 by Edward Thomson

tests: use a dummy homedir

Use a dummy home directory for tests to avoid user data leaking into
test execution.
parent f32ec999
...@@ -623,6 +623,24 @@ void cl_fake_globalconfig(git_str *out) ...@@ -623,6 +623,24 @@ void cl_fake_globalconfig(git_str *out)
git_str_dispose(&path); git_str_dispose(&path);
} }
void cl_sandbox_set_homedir(const char *home)
{
git_str path = GIT_STR_INIT;
if (home) {
git_libgit2_opts(GIT_OPT_SET_HOMEDIR, home);
} else {
git_str_joinpath(&path, clar_sandbox_path(), "__home");
if (!git_fs_path_exists(path.ptr))
cl_must_pass(p_mkdir(path.ptr, 0777));
git_libgit2_opts(GIT_OPT_SET_HOMEDIR, path.ptr);
}
git_str_dispose(&path);
}
void cl_sandbox_set_search_path_defaults(void) void cl_sandbox_set_search_path_defaults(void)
{ {
git_str path = GIT_STR_INIT; git_str path = GIT_STR_INIT;
......
...@@ -249,6 +249,7 @@ void cl_fake_homedir_cleanup(void *); ...@@ -249,6 +249,7 @@ void cl_fake_homedir_cleanup(void *);
void cl_fake_globalconfig(git_str *); void cl_fake_globalconfig(git_str *);
void cl_fake_globalconfig_cleanup(void *); void cl_fake_globalconfig_cleanup(void *);
void cl_sandbox_set_homedir(const char *);
void cl_sandbox_set_search_path_defaults(void); void cl_sandbox_set_search_path_defaults(void);
void cl_sandbox_disable_ownership_validation(void); void cl_sandbox_disable_ownership_validation(void);
......
...@@ -25,6 +25,7 @@ int main(int argc, char *argv[]) ...@@ -25,6 +25,7 @@ int main(int argc, char *argv[])
} }
cl_global_trace_register(); cl_global_trace_register();
cl_sandbox_set_homedir(getenv("CLAR_HOMEDIR"));
cl_sandbox_set_search_path_defaults(); cl_sandbox_set_search_path_defaults();
cl_sandbox_disable_ownership_validation(); cl_sandbox_disable_ownership_validation();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment