From d0078bf05c57948c74bed7ee54af8c08052df7f3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 6 Aug 2026 12:00:18 +0200 Subject: [PATCH] Recognize conflict markers that have no label Git only writes the space after a marker when there is a label to write after it, and the label can be empty: `git checkout -m` with the diff3 conflict style, for instance, has no name for the common ancestor, so it writes a bare "|||||||" line. --- pkg/gui/mergeconflicts/find_conflicts.go | 6 ++++-- pkg/gui/mergeconflicts/find_conflicts_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/gui/mergeconflicts/find_conflicts.go b/pkg/gui/mergeconflicts/find_conflicts.go index a296baf74..e57c16635 100644 --- a/pkg/gui/mergeconflicts/find_conflicts.go +++ b/pkg/gui/mergeconflicts/find_conflicts.go @@ -108,10 +108,12 @@ func hasMarkerPrefix[T string | []byte](line T, markerChar byte, markerSize int) } // A start, ancestor or end marker is followed by a space and a label, e.g. -// "<<<<<<< HEAD". +// "<<<<<<< HEAD". The label can be missing though, in which case git doesn't +// write the space either; `git checkout -m` with the diff3 conflict style does +// that for the ancestor marker, for example. func isConflictMarker[T string | []byte](line T, markerChar byte, markerSize int) bool { return hasMarkerPrefix(line, markerChar, markerSize) && - len(line) > markerSize && line[markerSize] == ' ' + (len(line) == markerSize || line[markerSize] == ' ') } // The marker separating the two sides of a conflict never has a label after it. diff --git a/pkg/gui/mergeconflicts/find_conflicts_test.go b/pkg/gui/mergeconflicts/find_conflicts_test.go index 97a61a3c4..28839126f 100644 --- a/pkg/gui/mergeconflicts/find_conflicts_test.go +++ b/pkg/gui/mergeconflicts/find_conflicts_test.go @@ -61,6 +61,19 @@ func TestDetermineLineType(t *testing.T) { line: "<<<<<<<<", expected: NOT_A_MARKER, }, + // Markers without a label + { + line: "<<<<<<<", + expected: START, + }, + { + line: "|||||||", + expected: ANCESTOR, + }, + { + line: ">>>>>>>", + expected: END, + }, { line: strings.Repeat("<", 32) + " HEAD", markerSize: 32, @@ -136,6 +149,10 @@ func TestFindConflictsAux(t *testing.T) { content: " <<<<<<< ", expected: false, }, + { + content: ">>>>>>>", + expected: true, + }, { content: "a\nb\nc\n<<<<<<< ", expected: true,