Skip to content

git_merge: files with merge attribute unset are merged as though they are text files #5328

Description

@lrm29

Reproduction steps

Add the following test to test/merge/driver.c:

void test_merge_driver__binary(void)
{
const char *expected = "this file is changed in master and branch\n";
const git_index_entry *ancestor, *ours, *theirs;

// Make merge do a binary merge for conflicting.txt by writing "*.txt -merge" to the
// .gitattributes file.
git_buf line = GIT_BUF_INIT;
git_buf_printf(&line, "*.txt -merge\n");
cl_assert(!git_buf_oom(&line));
cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", line.ptr);
git_buf_dispose(&line);


merge_branch();


cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
repo_index, "conflicting.txt"));

cl_assert_equal_file(expected, strlen(expected),
TEST_REPO_PATH "/conflicting.txt");
}

Here it is in a branch on my fork:

master...lrm29:git_merge_checkout_binary_contains_conflict_markers

The test first writes "*.txt -merge" to the .gitattributes file. It then calls the function merge_branch(), which is defined in tests/merge/driver.c and is a small wrapper around the function git_merge.

The first assertion shows that conflicting.txt is correctly identified as a conflict.

The second assertion that checks the contents of conflicting.txt fails. The problem is that even though "*.txt -merge" has been written to the .gitattributes file, a text merge has been performed when creating the contents of conflicting.txt in the working tree.

Expected behavior

Contents of conflicting.txt are:

this file is changed in master and branch

Actual behavior

Contents of conflicting.txt are:

 <<<<<<< HEAD
 this file is changed in master and branch
 =======
 this file is changed in branch and master
 >>>>>>>

Version of libgit2 (release number or SHA1)

6bd37c3

Operating system(s) tested

Debian 9, but will be OS agnostic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions