Skip to content

Commit 3f0caa1

Browse files
committed
repo::init tests: refactor global config path override
Provide a function that allows tests to set up a bespoke global configuration path.
1 parent 820e1e9 commit 3f0caa1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tests/repo/init.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ static void cleanup_repository(void *path)
4848
cl_fixture_cleanup((const char *)path);
4949
}
5050

51+
static void configure_tmp_global_path(git_buf *out)
52+
{
53+
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
54+
GIT_CONFIG_LEVEL_GLOBAL, &_tmp_path));
55+
cl_git_pass(git_buf_puts(&_tmp_path, ".tmp"));
56+
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
57+
GIT_CONFIG_LEVEL_GLOBAL, _tmp_path.ptr));
58+
59+
cl_must_pass(p_mkdir(_tmp_path.ptr, 0777));
60+
61+
cl_git_pass(git_buf_joinpath(out, _tmp_path.ptr, ".gitconfig"));
62+
}
63+
5164
static void ensure_repository_init(
5265
const char *working_directory,
5366
int is_bare,
@@ -572,15 +585,7 @@ static void configure_templatedir(const char *template_path)
572585
git_buf config_path = GIT_BUF_INIT;
573586
git_buf config_data = GIT_BUF_INIT;
574587

575-
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
576-
GIT_CONFIG_LEVEL_GLOBAL, &_tmp_path));
577-
cl_git_pass(git_buf_puts(&_tmp_path, ".tmp"));
578-
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
579-
GIT_CONFIG_LEVEL_GLOBAL, _tmp_path.ptr));
580-
581-
cl_must_pass(p_mkdir(_tmp_path.ptr, 0777));
582-
583-
cl_git_pass(git_buf_joinpath(&config_path, _tmp_path.ptr, ".gitconfig"));
588+
configure_tmp_global_path(&config_path);
584589

585590
cl_git_pass(git_buf_printf(&config_data,
586591
"[init]\n\ttemplatedir = \"%s\"\n", template_path));

0 commit comments

Comments
 (0)