void test_config_write__overwrite_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)); /* Update that entry */ cl_git_pass(git_config_set_string(cfg, entry_name, "newurl")); /* Reopen the file and make sure the entry was updated */ git_config_entry_free(entry); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, file_name)); cl_git_pass(git_config_get_entry(&entry, cfg, entry_name)); cl_assert_equal_s("newurl", entry->value); /* Cleanup */ git_config_entry_free(entry); git_config_free(cfg); }
static int attr_cache__lookup_path( char **out, git_config *cfg, const char *key, const char *fallback) { git_buf buf = GIT_BUF_INIT; int error; git_config_entry *entry = NULL; *out = NULL; if ((error = git_config__lookup_entry(&entry, cfg, key, false)) < 0) return error; if (entry) { const char *cfgval = entry->value; /* expand leading ~/ as needed */ if (cfgval && cfgval[0] == '~' && cfgval[1] == '/' && !git_sysdir_find_global_file(&buf, &cfgval[2])) *out = git_buf_detach(&buf); else if (cfgval) *out = git__strdup(cfgval); } else if (!git_sysdir_find_xdg_file(&buf, fallback)) *out = git_buf_detach(&buf); git_config_entry_free(entry); git_buf_free(&buf); return error; }
CString CSettingGitCredential::Load(CString key) { CString cmd; if (m_strUrl.IsEmpty()) cmd.Format(_T("credential.%s"), key); else cmd.Format(_T("credential.%s.%s"), m_strUrl, key); CAutoConfig config(true); int sel = m_ctrlConfigType.GetCurSel(); if (sel == ConfigType::Local) { git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitLocalConfig()), GIT_CONFIG_LEVEL_LOCAL, FALSE); } else if (sel == ConfigType::Global) { git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitGlobalConfig()), GIT_CONFIG_LEVEL_GLOBAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitGlobalXDGConfig()), GIT_CONFIG_LEVEL_XDG, FALSE); } else if (sel == ConfigType::System) { git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitSystemConfig()), GIT_CONFIG_LEVEL_SYSTEM, FALSE); } CStringA cmdA = CUnicodeUtils::GetUTF8(cmd); CStringA valueA; git_config_entry* entry; if (!git_config_get_entry(&entry, config, cmdA)) valueA = CStringA(entry->value); git_config_entry_free(entry); return CUnicodeUtils::GetUnicode(valueA); }
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_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_read__read_git_config_entry(void) { git_config *cfg; git_config_entry *entry; 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_get_entry(&entry, cfg, "core.dummy2")); cl_assert_equal_s("core.dummy2", entry->name); cl_assert_equal_s("42", entry->value); cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level); git_config_entry_free(entry); git_config_free(cfg); }
int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar) { int error = 0; struct map_data *data = &_cvar_maps[(int)cvar]; git_config_entry *entry; if ((error = git_config__lookup_entry(&entry, config, data->cvar_name, false)) < 0) return error; if (!entry) *out = data->default_value; else if (data->maps) error = git_config_lookup_map_value( out, data->maps, data->map_count, entry->value); else error = git_config_parse_bool(out, entry->value); git_config_entry_free(entry); return error; }