void test_config_global__open_global(void) { git_config *cfg, *global, *selected, *dummy; cl_git_pass(git_config_open_default(&cfg)); cl_git_pass(git_config_open_level(&global, cfg, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_fail(git_config_open_level(&dummy, cfg, GIT_CONFIG_LEVEL_XDG)); cl_git_pass(git_config_open_global(&selected, cfg)); git_config_free(selected); git_config_free(global); git_config_free(cfg); }
/* * At the beginning of the test: * - config9 has: core.dummy2=42 * - config15 has: core.dummy2=7 */ void test_config_write__delete_value_at_specific_level(void) { git_config *cfg, *cfg_specific; int32_t i; cl_git_pass(git_config_open_ondisk(&cfg, "config15")); cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); cl_assert(i == 7); git_config_free(cfg); cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, "config9", GIT_CONFIG_LEVEL_LOCAL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, "config15", GIT_CONFIG_LEVEL_GLOBAL, 0)); cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_pass(git_config_delete_entry(cfg_specific, "core.dummy2")); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config15")); cl_assert(git_config_get_int32(&i, cfg, "core.dummy2") == GIT_ENOTFOUND); cl_git_pass(git_config_set_int32(cfg, "core.dummy2", 7)); git_config_free(cfg_specific); git_config_free(cfg); }
void test_repo_config__can_open_missing_global_with_separators(void) { git_repository *repo; git_config *config, *global; cl_git_pass(git_buf_printf( &path, "%c%s", GIT_PATH_LIST_SEPARATOR, "dummy")); 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_dispose(&path); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_open_level( &global, config, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_pass(git_config_set_string(global, "test.set", "42")); git_config_free(global); git_config_free(config); git_repository_free(repo); }
/* * At the beginning of the test, config18 has: * int32global = 28 * int64global = 9223372036854775803 * boolglobal = true * stringglobal = I'm a global config value! * * And config19 has: * int32global = -1 * int64global = -2 * boolglobal = false * stringglobal = don't find me! * */ void test_config_read__simple_read_from_specific_level(void) { git_config *cfg, *cfg_specific; int i; int64_t l, expected = +9223372036854775803; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"), GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global")); cl_assert_equal_i(28, i); cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global")); cl_assert(l == expected); cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal")); cl_assert_equal_b(true, i); cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal")); cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf)); git_config_free(cfg_specific); git_config_free(cfg); }
void test_repo_init__symlinks_win32_enabled_by_global_config(void) { #ifndef GIT_WIN32 cl_skip(); #else git_config *config, *repo_config; int val; if (!filesystem_supports_symlinks("link")) cl_skip(); create_tmp_global_config("tmp_global_config", "core.symlinks", "true"); /* * Create a new repository (can't use `assert_config_on_init` since we * want to examine configuration levels with more granularity.) */ cl_git_pass(git_repository_init(&_repo, "config_entry/test.non.bare.git", false)); /* Ensure that core.symlinks remains set (via the global config). */ cl_git_pass(git_repository_config(&config, _repo)); cl_git_pass(git_config_get_bool(&val, config, "core.symlinks")); cl_assert_equal_i(1, val); /* * Ensure that the repository config does not set core.symlinks. * It should remain inherited. */ cl_git_pass(git_config_open_level(&repo_config, config, GIT_CONFIG_LEVEL_LOCAL)); cl_git_fail_with(GIT_ENOTFOUND, git_config_get_bool(&val, repo_config, "core.symlinks")); git_config_free(repo_config); git_config_free(config); #endif }
void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_returns_ENOTFOUND(void) { git_config *cfg; git_config *local_cfg; cl_git_pass(git_config_new(&cfg)); cl_assert_equal_i(GIT_ENOTFOUND, git_config_open_level(&local_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL)); git_config_free(cfg); }
static int repo_local_config( git_config **out, git_buf *config_dir, git_repository *repo, const char *repo_dir) { int error = 0; git_config *parent; const char *cfg_path; if (git_buf_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0) return -1; cfg_path = git_buf_cstr(config_dir); /* make LOCAL config if missing */ if (!git_path_isfile(cfg_path) && (error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0) return error; /* if no repo, just open that file directly */ if (!repo) return git_config_open_ondisk(out, cfg_path); /* otherwise, open parent config and get that level */ if ((error = git_repository_config__weakptr(&parent, repo)) < 0) return error; if (git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL) < 0) { giterr_clear(); if (!(error = git_config_add_file_ondisk( parent, cfg_path, GIT_CONFIG_LEVEL_LOCAL, false))) error = git_config_open_level(out, parent, GIT_CONFIG_LEVEL_LOCAL); } git_config_free(parent); return error; }
void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void) { git_config *cfg; git_config *single_level_cfg; const char *s; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"), GIT_CONFIG_LEVEL_GLOBAL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"), GIT_CONFIG_LEVEL_LOCAL, 0)); cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL)); git_config_free(cfg); cl_git_pass(git_config_get_string(&s, single_level_cfg, "core.stringglobal")); cl_assert_equal_s("don't find me!", s); git_config_free(single_level_cfg); }
void test_config_global__open_xdg(void) { git_config *cfg, *xdg, *selected; const char *str = "teststring"; const char *key = "this.variable"; git_buf buf = {0}; cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n"); cl_git_pass(git_config_open_default(&cfg)); cl_git_pass(git_config_open_level(&xdg, cfg, GIT_CONFIG_LEVEL_XDG)); cl_git_pass(git_config_open_global(&selected, cfg)); cl_git_pass(git_config_set_string(xdg, key, str)); cl_git_pass(git_config_get_string_buf(&buf, selected, key)); cl_assert_equal_s(str, buf.ptr); git_buf_free(&buf); git_config_free(selected); git_config_free(xdg); git_config_free(cfg); }
void test_config_write__add_value_at_specific_level(void) { git_config *cfg, *cfg_specific; int i; int64_t l, expected = +9223372036854775803; git_buf buf = GIT_BUF_INIT; // open config15 as global level config file cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, "config9", GIT_CONFIG_LEVEL_LOCAL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, "config15", GIT_CONFIG_LEVEL_GLOBAL, 0)); cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28)); cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected)); cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true)); cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!")); git_config_free(cfg_specific); git_config_free(cfg); // open config15 as local level config file cl_git_pass(git_config_open_ondisk(&cfg, "config15")); cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global")); cl_assert_equal_i(28, i); cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global")); cl_assert(l == expected); cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal")); cl_assert_equal_b(true, i); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal")); cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf)); git_buf_free(&buf); git_config_free(cfg); }
void test_repo_config__can_open_global_when_there_is_no_file(void) { git_repository *repo; git_config *config, *global; 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)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_open_level( &global, config, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_pass(git_config_set_string(global, "test.set", "42")); git_config_free(global); git_config_free(config); git_repository_free(repo); }
void test_repo_init__init_with_initial_commit(void) { git_index *index; cl_set_cleanup(&cleanup_repository, "committed"); /* Initialize the repository */ cl_git_pass(git_repository_init(&_repo, "committed", 0)); /* Index will be automatically created when requested for a new repo */ cl_git_pass(git_repository_index(&index, _repo)); /* Create a file so we can commit it * * If you are writing code outside the test suite, you can create this * file any way that you like, such as: * FILE *fp = fopen("committed/file.txt", "w"); * fputs("some stuff\n", fp); * fclose(fp); * We like to use the help functions because they do error detection * in a way that's easily compatible with our test suite. */ cl_git_mkfile("committed/file.txt", "some stuff\n"); /* Add file to the index */ cl_git_pass(git_index_add_bypath(index, "file.txt")); cl_git_pass(git_index_write(index)); /* Intentionally not using cl_repo_commit_from_index here so this code * can be used as an example of how an initial commit is typically * made to a repository... */ /* Make sure we're ready to use git_signature_default :-) */ { git_config *cfg, *local; cl_git_pass(git_repository_config(&cfg, _repo)); cl_git_pass(git_config_open_level(&local, cfg, GIT_CONFIG_LEVEL_LOCAL)); cl_git_pass(git_config_set_string(local, "user.name", "Test User")); cl_git_pass(git_config_set_string(local, "user.email", "*****@*****.**")); git_config_free(local); git_config_free(cfg); } /* Create a commit with the new contents of the index */ { git_signature *sig; git_oid tree_id, commit_id; git_tree *tree; cl_git_pass(git_signature_default(&sig, _repo)); cl_git_pass(git_index_write_tree(&tree_id, index)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); cl_git_pass(git_commit_create_v( &commit_id, _repo, "HEAD", sig, sig, NULL, "First", tree, 0)); git_tree_free(tree); git_signature_free(sig); } git_index_free(index); }