Skip to content

Commit ff67b5e

Browse files
committed
tests: use a dummy homedir
Use a dummy home directory for tests to avoid user data leaking into test execution.
1 parent f32ec99 commit ff67b5e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tests/clar/clar_libgit2.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,24 @@ void cl_fake_globalconfig(git_str *out)
623623
git_str_dispose(&path);
624624
}
625625

626+
void cl_sandbox_set_homedir(const char *home)
627+
{
628+
git_str path = GIT_STR_INIT;
629+
630+
if (home) {
631+
git_libgit2_opts(GIT_OPT_SET_HOMEDIR, home);
632+
} else {
633+
git_str_joinpath(&path, clar_sandbox_path(), "__home");
634+
635+
if (!git_fs_path_exists(path.ptr))
636+
cl_must_pass(p_mkdir(path.ptr, 0777));
637+
638+
git_libgit2_opts(GIT_OPT_SET_HOMEDIR, path.ptr);
639+
}
640+
641+
git_str_dispose(&path);
642+
}
643+
626644
void cl_sandbox_set_search_path_defaults(void)
627645
{
628646
git_str path = GIT_STR_INIT;

tests/clar/clar_libgit2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ void cl_fake_homedir_cleanup(void *);
249249
void cl_fake_globalconfig(git_str *);
250250
void cl_fake_globalconfig_cleanup(void *);
251251

252+
void cl_sandbox_set_homedir(const char *);
252253
void cl_sandbox_set_search_path_defaults(void);
253254
void cl_sandbox_disable_ownership_validation(void);
254255

tests/clar/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int main(int argc, char *argv[])
2525
}
2626

2727
cl_global_trace_register();
28+
cl_sandbox_set_homedir(getenv("CLAR_HOMEDIR"));
2829
cl_sandbox_set_search_path_defaults();
2930
cl_sandbox_disable_ownership_validation();
3031

0 commit comments

Comments
 (0)