diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-04-23 23:54:36 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-05-04 15:41:33 +0300 |
commit | bf99390eefb66c03ad56cd5131078817092d3322 (patch) | |
tree | 43e72a664be86d490f12cdc33ea781381008cb2e /tests | |
parent | f79c7322a9b5dff4769ed02f3ce987ce7061e012 (diff) |
config: examine whole file when writing
Previously we would try to be clever when writing the configuration
file and try to stop parsing (and simply copy the rest of the old
file) when we either found the value we were trying to write,
or when we left the section that value was in, the assumption being
that there was no more work to do.
Regrettably, you can have another section with the same name later
in the file, and we must cope with that gracefully, thus we read the
whole file in order to write a new file.
Now, writing a file looks even more than reading. Pull the config
parsing out into its own function that can be used by both reading
and writing the configuration.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/config/write.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/config/write.c b/tests/config/write.c index 5e4e7e12b..60d900535 100644 --- a/tests/config/write.c +++ b/tests/config/write.c @@ -181,6 +181,43 @@ void test_config_write__overwrite_value_with_duplicate_header(void) 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; + + /* 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")); + + /* 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__write_subsection(void) { git_config *cfg; |