mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
Handle alternate merge conflict format; add tests
This commit is contained in:
parent
44f7fc6f7c
commit
e478c254d4
@ -104,6 +104,10 @@ func findConflicts(content string) []*mergeConflict {
|
|||||||
case "=======":
|
case "=======":
|
||||||
newConflict.middle = i
|
newConflict.middle = i
|
||||||
default:
|
default:
|
||||||
|
// Sometimes these lines look like "<<<<<<< HEAD:foo/bar/baz.go" so handle that case as well.
|
||||||
|
if strings.HasPrefix(trimmedLine, "<<<<<<< HEAD:") {
|
||||||
|
newConflict = &mergeConflict{start: i}
|
||||||
|
}
|
||||||
if strings.HasPrefix(trimmedLine, ">>>>>>> ") {
|
if strings.HasPrefix(trimmedLine, ">>>>>>> ") {
|
||||||
newConflict.end = i
|
newConflict.end = i
|
||||||
conflicts = append(conflicts, newConflict)
|
conflicts = append(conflicts, newConflict)
|
||||||
|
90
pkg/gui/mergeconflicts/state_test.go
Normal file
90
pkg/gui/mergeconflicts/state_test.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package mergeconflicts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFindConflicts(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
name string
|
||||||
|
content string
|
||||||
|
expected []*mergeConflict
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
content: "",
|
||||||
|
expected: []*mergeConflict{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "various conflicts",
|
||||||
|
content: `++<<<<<<< HEAD
|
||||||
|
foo
|
||||||
|
++=======
|
||||||
|
bar
|
||||||
|
++>>>>>>> branch
|
||||||
|
|
||||||
|
<<<<<<< HEAD: foo/bar/baz.go
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
=======
|
||||||
|
baz
|
||||||
|
>>>>>>> branch
|
||||||
|
|
||||||
|
++<<<<<<< MERGE_HEAD
|
||||||
|
foo
|
||||||
|
++=======
|
||||||
|
bar
|
||||||
|
++>>>>>>> branch
|
||||||
|
|
||||||
|
++<<<<<<< Updated upstream
|
||||||
|
foo
|
||||||
|
++=======
|
||||||
|
bar
|
||||||
|
++>>>>>>> branch
|
||||||
|
|
||||||
|
++<<<<<<< ours
|
||||||
|
foo
|
||||||
|
++=======
|
||||||
|
bar
|
||||||
|
++>>>>>>> branch
|
||||||
|
`,
|
||||||
|
expected: []*mergeConflict{
|
||||||
|
{
|
||||||
|
start: 0,
|
||||||
|
middle: 2,
|
||||||
|
end: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 6,
|
||||||
|
middle: 9,
|
||||||
|
end: 11,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 13,
|
||||||
|
middle: 15,
|
||||||
|
end: 17,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 19,
|
||||||
|
middle: 21,
|
||||||
|
end: 23,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 25,
|
||||||
|
middle: 27,
|
||||||
|
end: 29,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
t.Run(s.name, func(t *testing.T) {
|
||||||
|
assert.EqualValues(t, s.expected, findConflicts(s.content))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user