mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-23 08:56:21 +00:00
Merge pull request #2476 from linquize/config-lf-eof
When adding new config section, handle config file not ending with LF
This commit is contained in:
commit
ec813d83e7
@ -1522,6 +1522,9 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
|
|
||||||
git_filebuf_write(&file, reader->buffer.ptr, reader->buffer.size);
|
git_filebuf_write(&file, reader->buffer.ptr, reader->buffer.size);
|
||||||
|
|
||||||
|
if (reader->buffer.size > 0 && *(reader->buffer.ptr + reader->buffer.size - 1) != '\n')
|
||||||
|
git_filebuf_write(&file, "\n", 1);
|
||||||
|
|
||||||
/* And now if we just need to add a variable */
|
/* And now if we just need to add a variable */
|
||||||
if (!section_matches && write_section(&file, section) < 0)
|
if (!section_matches && write_section(&file, section) < 0)
|
||||||
goto rewrite_fail;
|
goto rewrite_fail;
|
||||||
@ -1536,9 +1539,6 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If we are here, there is at least a section line */
|
/* If we are here, there is at least a section line */
|
||||||
if (reader->buffer.size > 0 && *(reader->buffer.ptr + reader->buffer.size - 1) != '\n')
|
|
||||||
git_filebuf_write(&file, "\n", 1);
|
|
||||||
|
|
||||||
q = quotes_for_value(value);
|
q = quotes_for_value(value);
|
||||||
git_filebuf_printf(&file, "\t%s = %s%s%s\n", name, q, value, q);
|
git_filebuf_printf(&file, "\t%s = %s%s%s\n", name, q, value, q);
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,22 @@ void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void)
|
|||||||
git_config_free(cfg);
|
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_which_needs_quotes(void)
|
void test_config_write__add_value_which_needs_quotes(void)
|
||||||
{
|
{
|
||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
|
Loading…
Reference in New Issue
Block a user