diff --git a/pkg/integration/tests/conflicts/conflict_marker_size_not_auto_staged.go b/pkg/integration/tests/conflicts/conflict_marker_size_not_auto_staged.go new file mode 100644 index 000000000..2b32ddd61 --- /dev/null +++ b/pkg/integration/tests/conflicts/conflict_marker_size_not_auto_staged.go @@ -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() + }, +}) diff --git a/pkg/integration/tests/conflicts/conflict_marker_size_resolve.go b/pkg/integration/tests/conflicts/conflict_marker_size_resolve.go new file mode 100644 index 000000000..6e40c633f --- /dev/null +++ b/pkg/integration/tests/conflicts/conflict_marker_size_resolve.go @@ -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")) + }, +}) diff --git a/pkg/integration/tests/shared/conflicts.go b/pkg/integration/tests/shared/conflicts.go index b84c8c7ad..c8319acf4 100644 --- a/pkg/integration/tests/shared/conflicts.go +++ b/pkg/integration/tests/shared/conflicts.go @@ -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. diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index bc2c25e09..15ef6f8c7 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -165,6 +165,8 @@ var tests = []*components.IntegrationTest{ config.NegativeRefspec, config.RemoteNamedStar, config.SidePanelsInPerRepoConfig, + conflicts.ConflictMarkerSizeNotAutoStaged, + conflicts.ConflictMarkerSizeResolve, conflicts.ContinuePromptDismissedWhenResolvedExternally, conflicts.Filter, conflicts.MergeFileBoth,