int main(int argc, char *argv[]) #endif { int res; #if defined(GIT_MSVC_CRTDBG) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); #endif clar_test_init(argc, argv); git_libgit2_init(); cl_global_trace_register(); cl_sandbox_set_search_path_defaults(); /* Run the test suite */ res = clar_test_run(); clar_test_shutdown(); cl_global_trace_disable(); git_libgit2_shutdown(); return res; }
int main(int argc, char *argv[]) #endif { int res; char *at_exit_cmd; clar_test_init(argc, argv); res = git_libgit2_init(); if (res < 0) { fprintf(stderr, "failed to init libgit2"); return res; } cl_global_trace_register(); cl_sandbox_set_search_path_defaults(); /* Run the test suite */ res = clar_test_run(); clar_test_shutdown(); cl_global_trace_disable(); git_libgit2_shutdown(); at_exit_cmd = getenv("CLAR_AT_EXIT"); if (at_exit_cmd != NULL) { int at_exit = system(at_exit_cmd); return res || at_exit; } return res; }
void test_repo_config__cleanup(void) { cl_sandbox_set_search_path_defaults(); git_buf_dispose(&path); cl_git_pass( git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES)); cl_assert(!git_path_isdir("alternate")); cl_fixture_cleanup("empty_standard_repo"); }
void test_repo_open__no_config(void) { git_buf path = GIT_BUF_INIT; git_repository *repo; git_config *config; cl_fixture_sandbox("empty_standard_repo"); cl_git_pass(cl_rename( "empty_standard_repo/.gitted", "empty_standard_repo/.git")); /* remove local config */ cl_git_pass(git_futils_rmdir_r( "empty_standard_repo/.git/config", NULL, GIT_RMDIR_REMOVE_FILES)); /* isolate from system level configs */ cl_must_pass(p_mkdir("alternate", 0777)); cl_git_pass(git_path_prettify(&path, "alternate", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); git_buf_free(&path); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_string(config, "test.set", "42")); git_config_free(config); git_repository_free(repo); cl_fixture_cleanup("empty_standard_repo"); cl_sandbox_set_search_path_defaults(); }
void test_config_global__cleanup(void) { cl_sandbox_set_search_path_defaults(); }
void test_repo_config__read_with_no_configs_at_all(void) { git_repository *repo; int val; cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); /* with none */ cl_must_pass(p_unlink("empty_standard_repo/.git/config")); cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(GIT_ABBREV_DEFAULT, val); git_repository_free(repo); /* with no local config, just system */ cl_sandbox_set_search_path_defaults(); cl_must_pass(p_mkdir("alternate/1", 0777)); cl_git_pass(git_buf_joinpath(&path, path.ptr, "1")); cl_git_rewritefile("alternate/1/gitconfig", "[core]\n\tabbrev = 10\n"); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(10, val); git_repository_free(repo); /* with just xdg + system */ cl_must_pass(p_mkdir("alternate/2", 0777)); path.ptr[path.size - 1] = '2'; cl_git_rewritefile("alternate/2/config", "[core]\n\tabbrev = 20\n"); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(20, val); git_repository_free(repo); /* with global + xdg + system */ cl_must_pass(p_mkdir("alternate/3", 0777)); path.ptr[path.size - 1] = '3'; cl_git_rewritefile("alternate/3/.gitconfig", "[core]\n\tabbrev = 30\n"); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(30, val); git_repository_free(repo); /* with all configs */ cl_git_rewritefile("empty_standard_repo/.git/config", "[core]\n\tabbrev = 40\n"); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(40, val); git_repository_free(repo); /* with all configs but delete the files ? */ cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(40, val); cl_must_pass(p_unlink("empty_standard_repo/.git/config")); cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); cl_must_pass(p_unlink("alternate/1/gitconfig")); cl_assert(!git_path_isfile("alternate/1/gitconfig")); cl_must_pass(p_unlink("alternate/2/config")); cl_assert(!git_path_isfile("alternate/2/config")); cl_must_pass(p_unlink("alternate/3/.gitconfig")); cl_assert(!git_path_isfile("alternate/3/.gitconfig")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(40, val); git_repository_free(repo); /* reopen */ cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); cl_assert(!git_path_isfile("alternate/3/.gitconfig")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(7, val); git_repository_free(repo); cl_assert(!git_path_exists("empty_standard_repo/.git/config")); cl_assert(!git_path_exists("alternate/3/.gitconfig")); }