git_config_free(cfg);
}
+#define FOO_COMMENT \
+ "; another comment!\n"
+
#define SECTION_FOO \
"\n" \
" \n" \
" # here's a comment\n" \
"\tname = \"value\"\n" \
" name2 = \"value2\"\n" \
- "; another comment!\n"
+
+#define SECTION_FOO_WITH_COMMENT SECTION_FOO FOO_COMMENT
#define SECTION_BAR \
"[section \"bar\"]\t\n" \
git_buf newfile = GIT_BUF_INIT;
/* This config can occur after removing and re-adding the origin remote */
- const char *file_content = SECTION_FOO SECTION_BAR;
+ 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_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);
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_free(cfg);
}
+
+void test_config_write__repeated(void)
+{
+ const char *filename = "config-repeated";
+ git_config *cfg;
+ git_buf result = GIT_BUF_INIT;
+ const char *expected = "[sample \"prefix\"]\n\
+\tsetting1 = someValue1\n\
+\tsetting2 = someValue2\n\
+\tsetting3 = someValue3\n\
+\tsetting4 = someValue4\n\
+";
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+ cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting1", "someValue1"));
+ cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting2", "someValue2"));
+ cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting3", "someValue3"));
+ cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting4", "someValue4"));
+ git_config_free(cfg);
+
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+
+ cl_git_pass(git_futils_readbuffer(&result, filename));
+ cl_assert_equal_s(expected, result.ptr);
+ git_buf_free(&result);
+
+ git_config_free(cfg);
+}