mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 02:24:25 -05:00
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:
@@ -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"))
|
||||
},
|
||||
})
|
||||
@@ -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.
|
||||
|
||||
@@ -165,6 +165,8 @@ var tests = []*components.IntegrationTest{
|
||||
config.NegativeRefspec,
|
||||
config.RemoteNamedStar,
|
||||
config.SidePanelsInPerRepoConfig,
|
||||
conflicts.ConflictMarkerSizeNotAutoStaged,
|
||||
conflicts.ConflictMarkerSizeResolve,
|
||||
conflicts.ContinuePromptDismissedWhenResolvedExternally,
|
||||
conflicts.Filter,
|
||||
conflicts.MergeFileBoth,
|
||||
|
||||
Reference in New Issue
Block a user