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); }
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); }
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_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); }
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); git_config * config; git_config_new(&config); int sel = m_ctrlConfigType.GetCurSel(); if (sel == ConfigType::Local) { CStringA projectConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitLocalConfig()); git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), GIT_CONFIG_LEVEL_LOCAL, FALSE); projectConfigA.ReleaseBuffer(); } else if (sel == ConfigType::Global) { CStringA globalConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalConfig()); git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), GIT_CONFIG_LEVEL_GLOBAL, FALSE); globalConfigA.ReleaseBuffer(); CStringA globalXDGConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalXDGConfig()); git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), GIT_CONFIG_LEVEL_XDG, FALSE); globalXDGConfigA.ReleaseBuffer(); } else if (sel == ConfigType::System) { CStringA systemConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitSystemConfig()); git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), GIT_CONFIG_LEVEL_SYSTEM, FALSE); systemConfigA.ReleaseBuffer(); } CStringA cmdA = CUnicodeUtils::GetUTF8(cmd); CStringA valueA; const git_config_entry *entry; if (!git_config_get_entry(&entry, config, cmdA)) valueA = CStringA(entry->value); cmdA.ReleaseBuffer(); git_config_free(config); return CUnicodeUtils::GetUnicode(valueA); }