Commit ae8f7260 by Edward Thomson

merge_files: don't add trailing newlines

When invoked with three files that each lack a trailing newline,
the merge result should also lack a trailing newline.
parent 286befeb
...@@ -249,3 +249,42 @@ void test_merge_files__automerge_whitespace_change(void) ...@@ -249,3 +249,42 @@ void test_merge_files__automerge_whitespace_change(void)
git_merge_file_result_free(&result); git_merge_file_result_free(&result);
} }
void test_merge_files__doesnt_add_newline(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
const char *expected = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen";
ancestor.ptr = "0\n1\n2\n3\n4\n5 XXX\n6YYY\n7\n8\n9\n10";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\n10";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100755;
theirs.ptr = "0\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen";
theirs.size = strlen(theirs.ptr);
theirs.path = "testfile.txt";
theirs.mode = 0100755;
opts.flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("testfile.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(strlen(expected), result.len);
cl_assert_equal_strn(expected, result.ptr, result.len);
git_merge_file_result_free(&result);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment