Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/engine/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,14 @@ func classifyConflictOutput(seg markers.ConflictSegment, output []byte) (markers
return markers.ResolutionNone, false, false, ConflictLabels{}, false
}

// Any surviving conflict marker means the user has not finished resolving
// this hunk. This also covers the case where ImportMerged's line-diff
// fallback wraps the markers with misaligned surrounding context — the
// extra text lives in adjacent TextSegments of the parsed output, but the
// hunk is still unresolved from the user's point of view, not a manual
// edit.
parsed, err := markers.Parse(output)
if err == nil && len(parsed.Conflicts) == 1 && len(parsed.Segments) == 1 {
if err == nil && len(parsed.Conflicts) >= 1 {
if unresolved, ok := parsed.Segments[parsed.Conflicts[0].SegmentIndex].(markers.ConflictSegment); ok {
return markers.ResolutionUnset, true, false, ConflictLabels{
OursLabel: unresolved.OursLabel,
Expand Down
42 changes: 42 additions & 0 deletions internal/engine/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,48 @@ func TestImportMergedPreservesCanonicalBaseLabelForTwoWayConflict(t *testing.T)
}
}

func TestClassifyConflictOutputTreatsSurvivingMarkersAsUnresolved(t *testing.T) {
// When ImportMerged's line-diff fallback fires (disk and diff3 draw
// different segment boundaries), conflict markers can end up wrapped in
// surrounding context text inside a single slot. The markers still
// indicate an unresolved hunk, not a manual edit — any other
// classification leaks raw `<<<<<<<` text into the result pane labelled
// as "manual resolved".
seg := markers.ConflictSegment{
Ours: []byte("ours\n"),
Theirs: []byte("theirs\n"),
}
output := []byte("before\n<<<<<<< HEAD\nours\n=======\ntheirs\n>>>>>>> branch\nafter\n")
res, unresolved, manual, _, _ := classifyConflictOutput(seg, output)
if res != markers.ResolutionUnset {
t.Fatalf("resolution = %q, want Unset", res)
}
if !unresolved {
t.Fatalf("unresolved = false, want true")
}
if manual {
t.Fatalf("manual = true, want false (markers still present)")
}
}

func TestClassifyConflictOutputMarkerFreeCustomTextIsManual(t *testing.T) {
seg := markers.ConflictSegment{
Ours: []byte("ours\n"),
Theirs: []byte("theirs\n"),
}
output := []byte("user typed a custom resolution here\n")
res, unresolved, manual, _, _ := classifyConflictOutput(seg, output)
if res != markers.ResolutionUnset {
t.Fatalf("resolution = %q, want Unset", res)
}
if unresolved {
t.Fatalf("unresolved = true, want false (no markers left)")
}
if !manual {
t.Fatalf("manual = false, want true")
}
}

func TestImportMergedRejectsReorderedSeparatedConflicts(t *testing.T) {
input := []byte("<<<<<<< left-one\nours1\n=======\ntheirs1\n>>>>>>> right-one\n<<<<<<< left-two\nours2\n=======\ntheirs2\n>>>>>>> right-two\n")
doc, err := markers.Parse(input)
Expand Down
Loading