Skip to content

merge: keep conflict markers on their own lines when hunks lack a trailing newline#85

Open
jochenhz wants to merge 1 commit into
bmwill:masterfrom
jochenhz:fix/merge-conflict-marker-newlines
Open

merge: keep conflict markers on their own lines when hunks lack a trailing newline#85
jochenhz wants to merge 1 commit into
bmwill:masterfrom
jochenhz:fix/merge-conflict-marker-newlines

Conversation

@jochenhz

Copy link
Copy Markdown

When a conflicting hunk sits at end-of-file without a trailing newline, merge/merge_bytes
glue the next conflict marker onto the content line, producing unparseable output:

    base:   "This is line 1.\nThis is line 2."
    ours:   "This is line 1.\nThis is line 2 changed."
    theirs: "This is line 1.\nThis is line 2 also changed."

Actual:

    This is line 1.
    <<<<<<< ours
    This is line 2 changed.||||||| original
    This is line 2.=======
    This is line 2 also changed.>>>>>>> theirs

Expected (matches git merge-file --diff3 on identical inputs):

    This is line 1.
    <<<<<<< ours
    This is line 2 changed.
    ||||||| original
    This is line 2.
    =======
    This is line 2 also changed.
    >>>>>>> theirs

add_conflict_marker/add_conflict_marker_bytes now prefix a newline when the output
doesn't already end with one. Only reachable for file-final hunks, so all existing merge
output is unchanged — the full suite passes untouched. One new test covers both the str
and bytes paths via assert_merge!.

A conflicting hunk at end-of-file without a trailing newline glued the
next marker onto its last content line, producing unparseable output.
Matches git merge-file --diff3 behavior.

Signed-off-by: Jochen Hunz <j.hunz@anchorpoint.app>
jochenhz added a commit to Anchorpoint-Software/lore that referenced this pull request Jul 18, 2026
Vendor diffy 0.4.2 with a newline guard in both conflict-marker
builders until a release contains the upstream fix
(bmwill/diffy#85).

Signed-off-by: Jochen Hunz <j.hunz@anchorpoint.app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant