void test_repo_init__reinit_overwrites_filemode(void) { git_config *config; int expected, current_value; #ifdef GIT_WIN32 expected = false; #else expected = true; #endif /* Init a new repo */ cl_set_cleanup(&cleanup_repository, "overwrite.git"); cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); /* Change the "core.filemode" config value to something unlikely */ git_repository_config(&config, _repo); git_config_set_bool(config, "core.filemode", !expected); git_config_free(config); git_repository_free(_repo); _repo = NULL; /* Reinit the repository */ cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); git_repository_config(&config, _repo); /* Ensure the "core.filemode" config value has been reset */ cl_git_pass(git_config_get_bool(¤t_value, config, "core.filemode")); cl_assert_equal_i(expected, current_value); git_config_free(config); }
void test_submodule_modify__init(void) { git_config *cfg; const char *str; /* erase submodule data from .git/config */ cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass( git_config_foreach_match(cfg, "submodule\\..*", delete_one_config, cfg)); git_config_free(cfg); /* confirm no submodule data in config */ cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url")); cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url")); git_config_free(cfg); /* call init and see that settings are copied */ cl_git_pass(git_submodule_foreach(g_repo, init_one_submodule, NULL)); git_submodule_reload_all(g_repo); /* confirm submodule data in config */ cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); cl_assert(git__suffixcmp(str, "/submod2_target") == 0); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url")); cl_assert(git__suffixcmp(str, "/submod2_target") == 0); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url")); cl_assert(git__suffixcmp(str, "/submod2_target") == 0); git_config_free(cfg); }
void test_config_write__value_containing_quotes(void) { git_config *cfg; git_buf buf = GIT_BUF_INIT; cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes")); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar")); cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf)); git_buf_clear(&buf); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar")); cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf)); git_buf_clear(&buf); git_config_free(cfg); /* The code path for values that already exist is different, check that one as well */ cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes")); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar")); cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf)); git_buf_clear(&buf); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar")); cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf)); git_buf_free(&buf); git_config_free(cfg); }
/* * This test exposes a bug where duplicate empty section headers could prevent * deletion of config entries. */ void test_config_write__delete_value_with_duplicate_header(void) { const char *file_name = "config-duplicate-header"; const char *entry_name = "remote.origin.url"; git_config *cfg; git_config_entry *entry; /* This config can occur after removing and re-adding the origin remote */ const char *file_content = "[remote \"origin\"]\n" \ "[branch \"master\"]\n" \ " remote = \"origin\"\n" \ "[remote \"origin\"]\n" \ " url = \"foo\"\n"; /* Write the test config and make sure the expected entry exists */ cl_git_mkfile(file_name, file_content); cl_git_pass(git_config_open_ondisk(&cfg, file_name)); cl_git_pass(git_config_get_entry(&entry, cfg, entry_name)); /* Delete that entry */ cl_git_pass(git_config_delete_entry(cfg, entry_name)); /* Reopen the file and make sure the entry no longer exists */ git_config_entry_free(entry); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, file_name)); cl_git_fail(git_config_get_entry(&entry, cfg, entry_name)); /* Cleanup */ git_config_entry_free(entry); git_config_free(cfg); }
void test_config_write__overwrite_multivar_within_duplicate_header(void) { const char *file_name = "config-duplicate-header"; const char *entry_name = "remote.origin.url"; git_config *cfg; git_config_entry *entry; int n = 0; /* This config can occur after removing and re-adding the origin remote */ const char *file_content = "[remote \"origin\"]\n" \ " url = \"bar\"\n" \ "[branch \"master\"]\n" \ " remote = \"origin\"\n" \ "[remote \"origin\"]\n" \ " url = \"foo\"\n"; /* Write the test config and make sure the expected entry exists */ cl_git_mkfile(file_name, file_content); cl_git_pass(git_config_open_ondisk(&cfg, file_name)); cl_git_pass(git_config_get_entry(&entry, cfg, entry_name)); /* Update that entry */ cl_git_pass(git_config_set_multivar(cfg, entry_name, ".*", "newurl")); git_config_entry_free(entry); git_config_free(cfg); /* Reopen the file and make sure the entry was updated */ cl_git_pass(git_config_open_ondisk(&cfg, file_name)); cl_git_pass(git_config_get_multivar_foreach(cfg, entry_name, NULL, multivar_cb, &n)); cl_assert_equal_i(2, n); /* Cleanup */ git_config_free(cfg); }
void test_config_read__single_line(void) { git_buf buf = GIT_BUF_INIT; git_config *cfg; cl_set_cleanup(&clean_test_config, NULL); cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"] var = value"); cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var")); cl_assert_equal_s(buf.ptr, "value"); git_buf_clear(&buf); cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var")); cl_assert_equal_s(buf.ptr, "value"); git_config_free(cfg); cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"]var = value"); cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); git_buf_clear(&buf); cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var")); cl_assert_equal_s(buf.ptr, "value"); git_buf_clear(&buf); cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var")); cl_assert_equal_s(buf.ptr, "value"); git_config_free(cfg); git_buf_dispose(&buf); }
/* * 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); }
/* * At the beginning of the test: * - config9 has: core.dummy2=42 * - config15 has: core.dummy2=7 * - config16 has: core.dummy2=28 */ void test_config_read__local_config_overrides_global_config_overrides_system_config(void) { git_config *cfg; int32_t i; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"), GIT_CONFIG_LEVEL_LOCAL, NULL, 0)); cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); cl_assert_equal_i(28, i); git_config_free(cfg); cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); cl_assert_equal_i(7, i); git_config_free(cfg); }
/* * 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__reinit_doesnot_overwrite_ignorecase(void) { git_config *config; int current_value; /* Init a new repo */ cl_set_cleanup(&cleanup_repository, "not.overwrite.git"); cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1)); /* Change the "core.ignorecase" config value to something unlikely */ git_repository_config(&config, _repo); git_config_set_int32(config, "core.ignorecase", 42); git_config_free(config); git_repository_free(_repo); _repo = NULL; /* Reinit the repository */ cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1)); git_repository_config(&config, _repo); /* Ensure the "core.ignorecase" config value hasn't been updated */ cl_git_pass(git_config_get_int32(¤t_value, config, "core.ignorecase")); cl_assert_equal_i(42, current_value); git_config_free(config); }
void test_config_write__value_containing_quotes(void) { git_config *cfg; const char* str; cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes")); cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); cl_assert_equal_s(str, "this \"has\" quotes"); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); cl_assert_equal_s(str, "this \"has\" quotes"); git_config_free(cfg); /* The code path for values that already exist is different, check that one as well */ cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes")); cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); cl_assert_equal_s(str, "this also \"has\" quotes"); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); cl_assert_equal_s(str, "this also \"has\" quotes"); git_config_free(cfg); }
void test_config_new__write_new_config(void) { git_config *config; git_buf buf = GIT_BUF_INIT; cl_git_mkfile(TEST_CONFIG, ""); cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); cl_git_pass(git_config_set_string(config, "color.ui", "auto")); cl_git_pass(git_config_set_string(config, "core.editor", "ed")); git_config_free(config); cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui")); cl_assert_equal_s("auto", git_buf_cstr(&buf)); git_buf_clear(&buf); cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor")); cl_assert_equal_s("ed", git_buf_cstr(&buf)); git_buf_free(&buf); git_config_free(config); p_unlink(TEST_CONFIG); }
void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void) { git_reference *original_ref, *new_ref; git_config *config; git_buf buf = GIT_BUF_INIT; char *original_remote, *original_merge; const char *str; cl_git_pass(git_repository_config_snapshot(&config, repo)); cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.remote")); original_remote = git_buf_detach(&buf); cl_git_pass(git_config_get_string_buf(&buf, config, "branch.master.merge")); original_merge = git_buf_detach(&buf); git_config_free(config); cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); cl_assert_equal_i(GIT_EEXISTS, git_branch_move(&new_ref, original_ref, "master", 0)); cl_assert(giterr_last()->message != NULL); cl_git_pass(git_repository_config_snapshot(&config, repo)); cl_git_pass(git_config_get_string(&str, config, "branch.master.remote")); cl_assert_equal_s(original_remote, str); cl_git_pass(git_config_get_string(&str, config, "branch.master.merge")); cl_assert_equal_s(original_merge, str); git_config_free(config); cl_assert_equal_i(GIT_EEXISTS, git_branch_move(&new_ref, original_ref, "cannot-fetch", 0)); cl_assert(giterr_last()->message != NULL); cl_git_pass(git_repository_config_snapshot(&config, repo)); cl_git_pass(git_config_get_string(&str, config, "branch.master.remote")); cl_assert_equal_s(original_remote, str); cl_git_pass(git_config_get_string(&str, config, "branch.master.merge")); cl_assert_equal_s(original_merge, str); git_config_free(config); git_reference_free(original_ref); cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/track-local")); cl_assert_equal_i(GIT_EEXISTS, git_branch_move(&new_ref, original_ref, "master", 0)); cl_assert(giterr_last()->message != NULL); cl_git_pass(git_repository_config_snapshot(&config, repo)); cl_git_pass(git_config_get_string(&str, config, "branch.master.remote")); cl_assert_equal_s(original_remote, str); cl_git_pass(git_config_get_string(&str, config, "branch.master.merge")); cl_assert_equal_s(original_merge, str); git__free(original_remote); git__free(original_merge); git_reference_free(original_ref); git_config_free(config); }
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); }
void test_config_write__add_value_which_needs_quotes(void) { git_config *cfg, *base; const char* str1; const char* str2; const char* str3; const char* str4; const char* str5; cl_git_pass(git_config_open_ondisk(&cfg, "config17")); cl_git_pass(git_config_set_string(cfg, "core.startwithspace", " Something")); cl_git_pass(git_config_set_string(cfg, "core.endwithspace", "Something ")); cl_git_pass(git_config_set_string(cfg, "core.containscommentchar1", "some#thing")); cl_git_pass(git_config_set_string(cfg, "core.containscommentchar2", "some;thing")); cl_git_pass(git_config_set_string(cfg, "core.startwhithsapceandcontainsdoublequote", " some\"thing")); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&base, "config17")); cl_git_pass(git_config_snapshot(&cfg, base)); cl_git_pass(git_config_get_string(&str1, cfg, "core.startwithspace")); cl_assert_equal_s(" Something", str1); cl_git_pass(git_config_get_string(&str2, cfg, "core.endwithspace")); cl_assert_equal_s("Something ", str2); cl_git_pass(git_config_get_string(&str3, cfg, "core.containscommentchar1")); cl_assert_equal_s("some#thing", str3); cl_git_pass(git_config_get_string(&str4, cfg, "core.containscommentchar2")); cl_assert_equal_s("some;thing", str4); cl_git_pass(git_config_get_string(&str5, cfg, "core.startwhithsapceandcontainsdoublequote")); cl_assert_equal_s(" some\"thing", str5); git_config_free(cfg); git_config_free(base); }
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_write__locking(void) { git_config *cfg, *cfg2; git_config_entry *entry; git_transaction *tx; const char *filename = "locked-file"; /* Open the config and lock it */ cl_git_mkfile(filename, "[section]\n\tname = value\n"); cl_git_pass(git_config_open_ondisk(&cfg, filename)); cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("value", entry->value); git_config_entry_free(entry); cl_git_pass(git_config_lock(&tx, cfg)); /* Change entries in the locked backend */ cl_git_pass(git_config_set_string(cfg, "section.name", "other value")); cl_git_pass(git_config_set_string(cfg, "section2.name3", "more value")); /* We can see that the file we read from hasn't changed */ cl_git_pass(git_config_open_ondisk(&cfg2, filename)); cl_git_pass(git_config_get_entry(&entry, cfg2, "section.name")); cl_assert_equal_s("value", entry->value); git_config_entry_free(entry); cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg2, "section2.name3")); git_config_free(cfg2); /* And we also get the old view when we read from the locked config */ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("value", entry->value); git_config_entry_free(entry); cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg, "section2.name3")); cl_git_pass(git_transaction_commit(tx)); git_transaction_free(tx); /* Now that we've unlocked it, we should see both updates */ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("other value", entry->value); git_config_entry_free(entry); cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3")); cl_assert_equal_s("more value", entry->value); git_config_entry_free(entry); git_config_free(cfg); /* We should also see the changes after reopening the config */ cl_git_pass(git_config_open_ondisk(&cfg, filename)); cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("other value", entry->value); git_config_entry_free(entry); cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3")); cl_assert_equal_s("more value", entry->value); git_config_entry_free(entry); git_config_free(cfg); }
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); }
void test_config_write__write_subsection(void) { git_config *cfg; const char *str; cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_string(cfg, "my.own.var", "works")); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_string(&str, cfg, "my.own.var")); cl_git_pass(strcmp(str, "works")); git_config_free(cfg); }
void test_config_write__add_section_at_file_with_no_clrf_at_the_end(void) { git_config *cfg; int i; cl_git_pass(git_config_open_ondisk(&cfg, "config17")); cl_git_pass(git_config_set_int32(cfg, "diff.context", 10)); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config17")); cl_git_pass(git_config_get_int32(&i, cfg, "diff.context")); cl_assert_equal_i(10, i); git_config_free(cfg); }
void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void) { git_config *cfg; int i; cl_git_pass(git_config_open_ondisk(&cfg, "config17")); cl_git_pass(git_config_set_int32(cfg, "core.newline", 7)); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config17")); cl_git_pass(git_config_get_int32(&i, cfg, "core.newline")); cl_assert_equal_i(7, i); git_config_free(cfg); }
void test_config_validkeyname__cleanup(void) { git_config_free(cfg); cfg = NULL; cl_fixture_cleanup("config10"); }
int Config_init(Config *self, PyObject *args, PyObject *kwds) { char *path = NULL; int err; if (kwds && PyDict_Size(kwds) > 0) { PyErr_SetString(PyExc_TypeError, "Config takes no keyword arguments"); return -1; } if (!PyArg_ParseTuple(args, "|s", &path)) return -1; if (path == NULL) err = git_config_new(&self->config); else err = git_config_open_ondisk(&self->config, path); if (err < 0) { git_config_free(self->config); if (err == GIT_ENOTFOUND) Error_set_exc(PyExc_IOError); else Error_set(err); return -1; } return 0; }
void test_config_write__write_subsection(void) { git_config *cfg; git_buf buf = GIT_BUF_INIT; cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_string(cfg, "my.own.var", "works")); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_string_buf(&buf, cfg, "my.own.var")); cl_assert_equal_s("works", git_buf_cstr(&buf)); git_buf_free(&buf); git_config_free(cfg); }
void test_status_worktree__new_staged_file_must_handle_crlf(void) { git_repository *repo; git_index *index; git_config *config; unsigned int status; cl_git_pass(git_repository_init(&repo, "getting_started", 0)); // Ensure that repo has core.autocrlf=true cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_bool(config, "core.autocrlf", true)); cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_from_workdir(index, "testfile.txt")); cl_git_pass(git_index_write(index)); cl_git_pass(git_status_file(&status, repo, "testfile.txt")); cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status); git_config_free(config); git_index_free(index); git_repository_free(repo); }
void cl_repo_set_bool(git_repository *repo, const char *cfg, int value) { git_config *config; cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_bool(config, cfg, value != 0)); git_config_free(config); }
void test_config_write__preserves_whitespace_and_comments(void) { const char *file_name = "config-duplicate-header"; const char *n; git_config *cfg; git_buf newfile = GIT_BUF_INIT; /* This config can occur after removing and re-adding the origin remote */ const char *file_content = SECTION_FOO_WITH_COMMENT SECTION_BAR; /* Write the test config and make sure the expected entry exists */ cl_git_mkfile(file_name, file_content); cl_git_pass(git_config_open_ondisk(&cfg, file_name)); cl_git_pass(git_config_set_string(cfg, "section.foo.other", "otherval")); cl_git_pass(git_config_set_string(cfg, "newsection.newname", "new_value")); /* Ensure that we didn't needlessly mangle the config file */ cl_git_pass(git_futils_readbuffer(&newfile, file_name)); n = newfile.ptr; cl_assert_equal_strn(SECTION_FOO, n, strlen(SECTION_FOO)); n += strlen(SECTION_FOO); cl_assert_equal_strn("\tother = otherval\n", n, strlen("\tother = otherval\n")); n += strlen("\tother = otherval\n"); cl_assert_equal_strn(FOO_COMMENT, n, strlen(FOO_COMMENT)); n += strlen(FOO_COMMENT); cl_assert_equal_strn(SECTION_BAR, n, strlen(SECTION_BAR)); n += strlen(SECTION_BAR); cl_assert_equal_s("[newsection]\n\tnewname = new_value\n", n); git_buf_free(&newfile); git_config_free(cfg); }
static int notes_ref_lookup(git_buf *out, git_rebase *rebase) { git_config *config = NULL; int do_rewrite, error; if (rebase->options.rewrite_notes_ref) { git_buf_attach_notowned(out, rebase->options.rewrite_notes_ref, strlen(rebase->options.rewrite_notes_ref)); return 0; } if ((error = git_repository_config(&config, rebase->repo)) < 0 || (error = git_config_get_bool(&do_rewrite, config, "notes.rewrite.rebase")) < 0) { if (error != GIT_ENOTFOUND) goto done; giterr_clear(); do_rewrite = 1; } error = do_rewrite ? git_config_get_string_buf(out, config, "notes.rewriteref") : GIT_ENOTFOUND; done: git_config_free(config); return error; }
PyObject * Repository_config__get__(Repository *self) { int err; git_config *config; Config *py_config; assert(self->repo); if (self->config == NULL) { err = git_repository_config(&config, self->repo); if (err < 0) return Error_set(err); py_config = PyObject_New(Config, &ConfigType); if (py_config == NULL) { git_config_free(config); return NULL; } py_config->config = config; self->config = (PyObject*)py_config; /* We need 2 refs here. One is returned, one is kept internally. */ Py_INCREF(self->config); } else { Py_INCREF(self->config); } return self->config; }
void test_attr_ignore__expand_tilde_to_homedir(void) { git_config *cfg; assert_is_ignored(false, "example.global_with_tilde"); cl_fake_home(); /* construct fake home with fake global excludes */ cl_git_mkfile("home/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")); git_config_free(cfg); git_attr_cache_flush(g_repo); /* must reset to pick up change */ assert_is_ignored(true, "example.global_with_tilde"); cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); cl_fake_home_cleanup(NULL); git_attr_cache_flush(g_repo); /* must reset to pick up change */ assert_is_ignored(false, "example.global_with_tilde"); }