Add tests demonstrating that we ignore the conflict-marker-size gitattribute

When a file's conflict markers aren't seven characters long we don't
recognize them at all. Two things go wrong: we consider the file's
conflicts resolved, so we stage it and offer to continue the merge a
moment after stopping at it; and pressing enter on it shows its diff
instead of the merge conflicts view, leaving no way to resolve it in
lazygit.
This commit is contained in:
Stefan Haller
2026-08-08 12:43:42 +02:00
parent bc9fafff02
commit c3450f9406
4 changed files with 112 additions and 0 deletions
@@ -0,0 +1,49 @@
package conflicts
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/integration/tests/shared"
)
var ConflictMarkerSizeNotAutoStaged = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Doesn't auto-stage an unresolved file whose conflict-marker-size gitattribute makes its markers longer than usual",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shared.SetCustomConflictMarkerSize(shell)
shared.CreateMergeConflictFile(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Common().PretendMergeOrRebaseStartedInLazygit()
t.Views().Files().
IsFocused().
Lines(
Contains("UU file").IsSelected(),
).
// Each refresh checks whether the conflicts are still there
Press(keys.Universal.Refresh).
/* EXPECTED:
// They are, so the file doesn't get staged and we don't get asked to
// continue the merge
Lines(
Contains("UU file").IsSelected(),
).
// Once they really are resolved, we do
Tap(func() {
t.Shell().UpdateFile("file", "resolved content")
}).
Press(keys.Universal.Refresh).
Tap(func() {
t.Common().ContinueOnConflictsResolved("merge")
}).
IsEmpty()
ACTUAL: */
Tap(func() {
t.Common().ContinueOnConflictsResolved("merge")
}).
IsEmpty()
},
})
@@ -0,0 +1,45 @@
package conflicts
import (
"strings"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/integration/tests/shared"
)
var ConflictMarkerSizeResolve = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Resolves a conflict in a file whose conflict-marker-size gitattribute makes its markers longer than usual",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shared.SetCustomConflictMarkerSize(shell)
shared.CreateMergeConflictFileMultiple(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
startMarker := strings.Repeat("<", shared.CustomConflictMarkerSize)
t.Views().Files().
IsFocused().
Lines(
Contains("UU file").IsSelected(),
).
PressEnter()
/* EXPECTED:
t.Views().MergeConflicts().
IsFocused().
SelectedLines(
Contains(startMarker+" HEAD"),
Contains("First Change"),
Contains(strings.Repeat("=", shared.CustomConflictMarkerSize)),
).
PressPrimaryAction().
Content(DoesNotContain(startMarker + " HEAD\nFirst Change"))
ACTUAL: */
// We don't recognize the markers, so instead of the merge conflicts view
// we get the file's diff
t.Views().Main().Content(Contains(startMarker + " HEAD"))
},
})
+16
View File
@@ -1,6 +1,8 @@
package shared
import (
"fmt"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
@@ -28,6 +30,20 @@ Second Change
File
`
// A conflict-marker-size that isn't git's default of 7. It's set for file types
// whose regular content tends to contain marker-looking lines, e.g.
// documentation about merging, or test scripts.
const CustomConflictMarkerSize = 32
// Makes git write conflict markers of CustomConflictMarkerSize characters into
// the file that the setups below create conflicts in. Call this before one of
// them.
var SetCustomConflictMarkerSize = func(shell *Shell) {
shell.CreateFileAndAdd(".gitattributes",
fmt.Sprintf("file conflict-marker-size=%d\n", CustomConflictMarkerSize)).
Commit("set a custom conflict marker size")
}
// prepares us for a rebase/merge that has conflicts
var MergeConflictsSetup = func(shell *Shell) {
shell.
+2
View File
@@ -165,6 +165,8 @@ var tests = []*components.IntegrationTest{
config.NegativeRefspec,
config.RemoteNamedStar,
config.SidePanelsInPerRepoConfig,
conflicts.ConflictMarkerSizeNotAutoStaged,
conflicts.ConflictMarkerSizeResolve,
conflicts.ContinuePromptDismissedWhenResolvedExternally,
conflicts.Filter,
conflicts.MergeFileBoth,