mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
test: isolate home directory separately from global config
This commit is contained in:
@@ -548,31 +548,61 @@ void clar__assert_equal_file(
|
||||
(size_t)expected_bytes, (size_t)total_bytes);
|
||||
}
|
||||
|
||||
static git_buf _cl_restore_home = GIT_BUF_INIT;
|
||||
static git_buf _cl_restore_homedir = GIT_BUF_INIT;
|
||||
|
||||
void cl_fake_home_cleanup(void *payload)
|
||||
void cl_fake_homedir_cleanup(void *payload)
|
||||
{
|
||||
GIT_UNUSED(payload);
|
||||
|
||||
if (_cl_restore_home.ptr) {
|
||||
if (_cl_restore_homedir.ptr) {
|
||||
cl_git_pass(git_libgit2_opts(
|
||||
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, _cl_restore_home.ptr));
|
||||
git_buf_dispose(&_cl_restore_home);
|
||||
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, _cl_restore_homedir.ptr));
|
||||
git_buf_dispose(&_cl_restore_homedir);
|
||||
}
|
||||
}
|
||||
|
||||
void cl_fake_home(void)
|
||||
void cl_fake_homedir(void)
|
||||
{
|
||||
git_str path = GIT_STR_INIT;
|
||||
|
||||
cl_git_pass(git_libgit2_opts(
|
||||
GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_home));
|
||||
GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_homedir));
|
||||
|
||||
cl_set_cleanup(cl_fake_home_cleanup, NULL);
|
||||
cl_set_cleanup(cl_fake_homedir_cleanup, NULL);
|
||||
|
||||
if (!git_fs_path_exists("home"))
|
||||
cl_must_pass(p_mkdir("home", 0777));
|
||||
cl_git_pass(git_fs_path_prettify(&path, "home", NULL));
|
||||
if (!git_fs_path_exists("homedir"))
|
||||
cl_must_pass(p_mkdir("homedir", 0777));
|
||||
cl_git_pass(git_fs_path_prettify(&path, "homedir", NULL));
|
||||
cl_git_pass(git_libgit2_opts(
|
||||
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
|
||||
git_str_dispose(&path);
|
||||
}
|
||||
|
||||
static git_buf _cl_restore_globalconfig = GIT_BUF_INIT;
|
||||
|
||||
void cl_fake_globalconfig_cleanup(void *payload)
|
||||
{
|
||||
GIT_UNUSED(payload);
|
||||
|
||||
if (_cl_restore_globalconfig.ptr) {
|
||||
cl_git_pass(git_libgit2_opts(
|
||||
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, _cl_restore_globalconfig.ptr));
|
||||
git_buf_dispose(&_cl_restore_globalconfig);
|
||||
}
|
||||
}
|
||||
|
||||
void cl_fake_globalconfig(void)
|
||||
{
|
||||
git_str path = GIT_STR_INIT;
|
||||
|
||||
cl_git_pass(git_libgit2_opts(
|
||||
GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_globalconfig));
|
||||
|
||||
cl_set_cleanup(cl_fake_globalconfig_cleanup, NULL);
|
||||
|
||||
if (!git_fs_path_exists("globalconfig"))
|
||||
cl_must_pass(p_mkdir("globalconfig", 0777));
|
||||
cl_git_pass(git_fs_path_prettify(&path, "globalconfig", NULL));
|
||||
cl_git_pass(git_libgit2_opts(
|
||||
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
|
||||
git_str_dispose(&path);
|
||||
|
||||
@@ -213,13 +213,23 @@ int cl_repo_get_bool(git_repository *repo, const char *cfg);
|
||||
|
||||
void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value);
|
||||
|
||||
/* set up a fake "home" directory and set libgit2 GLOBAL search path.
|
||||
/* set up a fake "home" directory
|
||||
*
|
||||
* automatically configures cleanup function to restore the regular search
|
||||
* path, although you can call it explicitly if you wish (with NULL).
|
||||
*/
|
||||
void cl_fake_home(void);
|
||||
void cl_fake_home_cleanup(void *);
|
||||
void cl_fake_homedir(void);
|
||||
void cl_fake_homedir_cleanup(void *);
|
||||
|
||||
|
||||
/*
|
||||
* set up a fake directory for the libgit2 GLOBAL search path.
|
||||
*
|
||||
* automatically configures cleanup function to restore the regular search
|
||||
* path, although you can call it explicitly if you wish (with NULL).
|
||||
*/
|
||||
void cl_fake_globalconfig(void);
|
||||
void cl_fake_globalconfig_cleanup(void *);
|
||||
|
||||
void cl_sandbox_set_search_path_defaults(void);
|
||||
void cl_sandbox_disable_ownership_validation(void);
|
||||
|
||||
@@ -290,10 +290,10 @@ void test_ignore_path__expand_tilde_to_homedir(void)
|
||||
|
||||
assert_is_ignored(false, "example.global_with_tilde");
|
||||
|
||||
cl_fake_home();
|
||||
cl_fake_globalconfig();
|
||||
|
||||
/* construct fake home with fake global excludes */
|
||||
cl_git_mkfile("home/globalexclude", "# found me\n*.global_with_tilde\n");
|
||||
cl_git_mkfile("globalconfig/globalexclude", "# found me\n*.global_with_tilde\n");
|
||||
|
||||
cl_git_pass(git_repository_config(&cfg, g_repo));
|
||||
cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexclude"));
|
||||
@@ -305,7 +305,7 @@ void test_ignore_path__expand_tilde_to_homedir(void)
|
||||
|
||||
cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
|
||||
|
||||
cl_fake_home_cleanup(NULL);
|
||||
cl_fake_globalconfig_cleanup(NULL);
|
||||
|
||||
git_attr_cache_flush(g_repo); /* must reset to pick up change */
|
||||
|
||||
|
||||
@@ -385,8 +385,8 @@ void test_ignore_status__leading_slash_ignores(void)
|
||||
|
||||
make_test_data(test_repo_1, test_files_1);
|
||||
|
||||
cl_fake_home();
|
||||
cl_git_mkfile("home/.gitignore", "/ignore_me\n");
|
||||
cl_fake_globalconfig();
|
||||
cl_git_mkfile("globalconfig/.gitignore", "/ignore_me\n");
|
||||
{
|
||||
git_config *cfg;
|
||||
cl_git_pass(git_repository_config(&cfg, g_repo));
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "remote.h"
|
||||
#include "futils.h"
|
||||
#include "refs.h"
|
||||
#include "sysdir.h"
|
||||
|
||||
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
|
||||
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
|
||||
@@ -606,7 +607,7 @@ void test_online_clone__ssh_github(void)
|
||||
if (!_github_ssh_pubkey || !_github_ssh_privkey)
|
||||
clar__skip();
|
||||
|
||||
cl_fake_homedir(NULL);
|
||||
cl_fake_homedir();
|
||||
|
||||
g_options.fetch_opts.callbacks.credentials = github_credentials;
|
||||
g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check;
|
||||
@@ -647,7 +648,7 @@ void test_online_clone__ssh_certcheck_accepts_unknown(void)
|
||||
if (!_github_ssh_pubkey || !_github_ssh_privkey)
|
||||
clar__skip();
|
||||
|
||||
cl_fake_homedir(NULL);
|
||||
cl_fake_homedir();
|
||||
|
||||
g_options.fetch_opts.callbacks.credentials = github_credentials;
|
||||
|
||||
@@ -678,7 +679,9 @@ void test_online_clone__ssh_certcheck_override_knownhosts(void)
|
||||
|
||||
g_options.fetch_opts.callbacks.credentials = github_credentials;
|
||||
|
||||
cl_fake_homedir(&knownhostsfile);
|
||||
cl_fake_homedir();
|
||||
|
||||
cl_git_pass(git_sysdir_find_homedir(&knownhostsfile));
|
||||
cl_git_pass(git_str_joinpath(&knownhostsfile, knownhostsfile.ptr, ".ssh"));
|
||||
cl_git_pass(p_mkdir(knownhostsfile.ptr, 0777));
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ static void assert_global_config_match(const char *config, const char *expected)
|
||||
|
||||
void test_remote_httpproxy__config_overrides_detached_remote(void)
|
||||
{
|
||||
cl_fake_home();
|
||||
cl_fake_globalconfig();
|
||||
|
||||
assert_global_config_match(NULL, NULL);
|
||||
assert_global_config_match("http.proxy", "http://localhost:1/");
|
||||
|
||||
Reference in New Issue
Block a user