Commit 2a8841ae by Edward Thomson

merge: test CR/LF conflicts for CR/LF files

Ensure that when the files being merged have CR/LF line endings that the
conflict markers produced in the conflict file also have CR/LF line
endings.
parent 7f52bc5a
...@@ -377,3 +377,51 @@ void test_merge_files__handles_binaries_when_favored(void) ...@@ -377,3 +377,51 @@ void test_merge_files__handles_binaries_when_favored(void)
git_merge_file_result_free(&result); git_merge_file_result_free(&result);
} }
void test_merge_files__crlf_conflict_markers_for_crlf_files(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 =
"<<<<<<< file.txt\r\nThis file\r\ndoes, too.\r\n"
"=======\r\nAnd so does\r\nthis one.\r\n>>>>>>> file.txt\r\n";
size_t expected_len = strlen(expected);
const char *expected_diff3 =
"<<<<<<< file.txt\r\nThis file\r\ndoes, too.\r\n"
"||||||| file.txt\r\nThis file has\r\nCRLF line endings.\r\n"
"=======\r\nAnd so does\r\nthis one.\r\n>>>>>>> file.txt\r\n";
size_t expected_diff3_len = strlen(expected_diff3);
ancestor.ptr = "This file has\r\nCRLF line endings.\r\n";
ancestor.size = 35;
ancestor.path = "file.txt";
ancestor.mode = 0100644;
ours.ptr = "This file\r\ndoes, too.\r\n";
ours.size = 23;
ours.path = "file.txt";
ours.mode = 0100644;
theirs.ptr = "And so does\r\nthis one.\r\n";
theirs.size = 24;
theirs.path = "file.txt";
theirs.mode = 0100644;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(0, result.automergeable);
cl_assert_equal_i(expected_len, result.len);
cl_assert(memcmp(expected, result.ptr, expected_len) == 0);
git_merge_file_result_free(&result);
opts.flags |= GIT_MERGE_FILE_STYLE_DIFF3;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(0, result.automergeable);
cl_assert_equal_i(expected_diff3_len, result.len);
cl_assert(memcmp(expected_diff3, result.ptr, expected_len) == 0);
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