Commit 41744745 by Carlos Martín Nieto

Merge pull request #3512 from ethomson/windows_sysdir

Protect windows SYSDIR when running tests
parents 32b9e647 88638f9b
......@@ -174,9 +174,9 @@ typedef enum {
* * opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf)
*
* > Get the search path for a given level of config data. "level" must
* > be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`, or
* > `GIT_CONFIG_LEVEL_XDG`. The search path is written to the `out`
* > buffer.
* > be one of `GIT_CONFIG_LEVEL_SYSTEM`, `GIT_CONFIG_LEVEL_GLOBAL`,
* > `GIT_CONFIG_LEVEL_XDG`, or `GIT_CONFIG_LEVEL_PROGRAMDATA`.
* > The search path is written to the `out` buffer.
*
* * opts(GIT_OPT_SET_SEARCH_PATH, int level, const char *path)
*
......@@ -188,8 +188,9 @@ typedef enum {
* > variables). Use magic path `$PATH` to include the old value
* > of the path (if you want to prepend or append, for instance).
* >
* > - `level` must be GIT_CONFIG_LEVEL_SYSTEM, GIT_CONFIG_LEVEL_GLOBAL,
* > or GIT_CONFIG_LEVEL_XDG.
* > - `level` must be `GIT_CONFIG_LEVEL_SYSTEM`,
* > `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or
* > `GIT_CONFIG_LEVEL_PROGRAMDATA`.
*
* * opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, git_otype type, size_t size)
*
......
......@@ -49,9 +49,18 @@ static int config_level_to_sysdir(int config_level)
int val = -1;
switch (config_level) {
case GIT_CONFIG_LEVEL_SYSTEM: val = GIT_SYSDIR_SYSTEM; break;
case GIT_CONFIG_LEVEL_XDG: val = GIT_SYSDIR_XDG; break;
case GIT_CONFIG_LEVEL_GLOBAL: val = GIT_SYSDIR_GLOBAL; break;
case GIT_CONFIG_LEVEL_SYSTEM:
val = GIT_SYSDIR_SYSTEM;
break;
case GIT_CONFIG_LEVEL_XDG:
val = GIT_SYSDIR_XDG;
break;
case GIT_CONFIG_LEVEL_GLOBAL:
val = GIT_SYSDIR_GLOBAL;
break;
case GIT_CONFIG_LEVEL_PROGRAMDATA:
val = GIT_SYSDIR_PROGRAMDATA;
break;
default:
giterr_set(
GITERR_INVALID, "Invalid config path selector %d", config_level);
......
......@@ -541,14 +541,23 @@ void cl_fake_home(void)
void cl_sandbox_set_search_path_defaults(void)
{
const char *sandbox_path = clar_sandbox_path();
git_buf path = GIT_BUF_INIT;
git_buf_joinpath(&path, clar_sandbox_path(), "__config");
if (!git_path_exists(path.ptr))
cl_must_pass(p_mkdir(path.ptr, 0777));
git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, sandbox_path);
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr);
git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, sandbox_path);
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr);
git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, sandbox_path);
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr);
git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_PROGRAMDATA, path.ptr);
git_buf_free(&path);
}
#ifdef GIT_WIN32
......
......@@ -68,7 +68,6 @@ void test_config_global__open_xdg(void)
void test_config_global__open_programdata(void)
{
char *programdata;
git_config *cfg;
git_repository *repo;
git_buf config_path = GIT_BUF_INIT;
......@@ -77,9 +76,12 @@ void test_config_global__open_programdata(void)
if (!cl_getenv("GITTEST_INVASIVE_FS_STRUCTURE"))
cl_skip();
programdata = cl_getenv("PROGRAMDATA");
cl_git_pass(git_buf_printf(&config_path, "%s/Git", programdata));
cl_git_pass(p_mkdir(config_path.ptr, 0777));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
GIT_CONFIG_LEVEL_PROGRAMDATA, &config_path));
if (!git_path_isdir(config_path.ptr))
cl_git_pass(p_mkdir(config_path.ptr, 0777));
cl_git_pass(git_buf_puts(&config_path, "/config"));
cl_git_pass(git_config_open_ondisk(&cfg, config_path.ptr));
......
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