1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/integration/tests/shared/conflicts.go
Jesse Duffield 63dc07fded Construct arg vector manually rather than parse string
By constructing an arg vector manually, we no longer need to quote arguments

Mandate that args must be passed when building a command

Now you need to provide an args array when building a command.
There are a handful of places where we need to deal with a string,
such as with user-defined custom commands, and for those we now require
that at the callsite they use str.ToArgv to do that. I don't want
to provide a method out of the box for it because I want to discourage its
use.

For some reason we were invoking a command through a shell when amending a
commit, and I don't believe we needed to do that as there was nothing user-
supplied about the command. So I've switched to using a regular command out-
side the shell there
2023-05-23 19:49:19 +10:00

160 lines
3.4 KiB
Go

package shared
import (
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var OriginalFileContent = `
This
Is
The
Original
File
`
var FirstChangeFileContent = `
This
Is
The
First Change
File
`
var SecondChangeFileContent = `
This
Is
The
Second Change
File
`
// prepares us for a rebase/merge that has conflicts
var MergeConflictsSetup = func(shell *Shell) {
shell.
NewBranch("original-branch").
EmptyCommit("one").
EmptyCommit("two").
EmptyCommit("three").
CreateFileAndAdd("file", OriginalFileContent).
Commit("original").
NewBranch("first-change-branch").
UpdateFileAndAdd("file", FirstChangeFileContent).
Commit("first change").
Checkout("original-branch").
NewBranch("second-change-branch").
UpdateFileAndAdd("file", SecondChangeFileContent).
Commit("second change").
EmptyCommit("second-change-branch unrelated change").
Checkout("first-change-branch")
}
var CreateMergeConflictFile = func(shell *Shell) {
MergeConflictsSetup(shell)
shell.RunCommandExpectError([]string{"git", "merge", "--no-edit", "second-change-branch"})
}
var CreateMergeCommit = func(shell *Shell) {
CreateMergeConflictFile(shell)
shell.UpdateFileAndAdd("file", SecondChangeFileContent)
shell.ContinueMerge()
}
// creates a merge conflict where there are two files with conflicts and a separate file without conflicts
var CreateMergeConflictFiles = func(shell *Shell) {
shell.
NewBranch("original-branch").
EmptyCommit("one").
EmptyCommit("two").
EmptyCommit("three").
CreateFileAndAdd("file1", OriginalFileContent).
CreateFileAndAdd("file2", OriginalFileContent).
Commit("original").
NewBranch("first-change-branch").
UpdateFileAndAdd("file1", FirstChangeFileContent).
UpdateFileAndAdd("file2", FirstChangeFileContent).
Commit("first change").
Checkout("original-branch").
NewBranch("second-change-branch").
UpdateFileAndAdd("file1", SecondChangeFileContent).
UpdateFileAndAdd("file2", SecondChangeFileContent).
// this file is not changed in the second branch
CreateFileAndAdd("file3", "content").
Commit("second change").
EmptyCommit("second-change-branch unrelated change").
Checkout("first-change-branch")
shell.RunCommandExpectError([]string{"git", "merge", "--no-edit", "second-change-branch"})
}
// These 'multiple' variants are just like the short ones but with longer file contents and with multiple conflicts within the file.
var OriginalFileContentMultiple = `
This
Is
The
Original
File
..
It
Is
Longer
Than
The
Other
Options
`
var FirstChangeFileContentMultiple = `
This
Is
The
First Change
File
..
It
Is
Longer
Than
The
Other
Other First Change
`
var SecondChangeFileContentMultiple = `
This
Is
The
Second Change
File
..
It
Is
Longer
Than
The
Other
Other Second Change
`
var CreateMergeConflictFileMultiple = func(shell *Shell) {
shell.
NewBranch("original-branch").
EmptyCommit("one").
EmptyCommit("two").
EmptyCommit("three").
CreateFileAndAdd("file", OriginalFileContentMultiple).
Commit("original").
NewBranch("first-change-branch").
UpdateFileAndAdd("file", FirstChangeFileContentMultiple).
Commit("first change").
Checkout("original-branch").
NewBranch("second-change-branch").
UpdateFileAndAdd("file", SecondChangeFileContentMultiple).
Commit("second change").
EmptyCommit("second-change-branch unrelated change").
Checkout("first-change-branch")
shell.RunCommandExpectError([]string{"git", "merge", "--no-edit", "second-change-branch"})
}