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,