mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-02 23:27:32 +02:00
fix tests
This commit is contained in:
parent
c6b57d9b57
commit
3621854dc7
@ -174,3 +174,7 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error {
|
|||||||
|
|
||||||
return self.cmd.New(command).Run()
|
return self.cmd.New(command).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *BranchCommands) AllBranchesLogCmdObj() oscommands.ICmdObj {
|
||||||
|
return self.cmd.New(self.UserConfig.Git.AllBranchesLogCmd).DontLog()
|
||||||
|
}
|
||||||
|
@ -5,10 +5,16 @@ import (
|
|||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandGetCommitDifferences(t *testing.T) {
|
func NewBranchCommandsWithRunner(runner *oscommands.FakeCmdObjRunner) *BranchCommands {
|
||||||
|
builder := oscommands.NewDummyCmdObjBuilder(runner)
|
||||||
|
return NewBranchCommands(utils.NewDummyCommon(), builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBranchGetCommitDifferences(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
@ -41,8 +47,8 @@ func TestGitCommandGetCommitDifferences(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := NewBranchCommandsWithRunner(s.runner)
|
||||||
pushables, pullables := gitCmd.Branch.GetCommitDifferences("HEAD", "@{u}")
|
pushables, pullables := instance.GetCommitDifferences("HEAD", "@{u}")
|
||||||
assert.EqualValues(t, s.expectedPushables, pushables)
|
assert.EqualValues(t, s.expectedPushables, pushables)
|
||||||
assert.EqualValues(t, s.expectedPullables, pullables)
|
assert.EqualValues(t, s.expectedPullables, pullables)
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
@ -50,16 +56,16 @@ func TestGitCommandGetCommitDifferences(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandNewBranch(t *testing.T) {
|
func TestBranchNewBranch(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
Expect(`git checkout -b "test" "master"`, "", nil)
|
Expect(`git checkout -b "test" "master"`, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := NewBranchCommandsWithRunner(runner)
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Branch.New("test", "master"))
|
assert.NoError(t, instance.New("test", "master"))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandDeleteBranch(t *testing.T) {
|
func TestBranchDeleteBranch(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
force bool
|
force bool
|
||||||
@ -88,24 +94,24 @@ func TestGitCommandDeleteBranch(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := NewBranchCommandsWithRunner(s.runner)
|
||||||
|
|
||||||
s.test(gitCmd.Branch.Delete("test", s.force))
|
s.test(instance.Delete("test", s.force))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandMerge(t *testing.T) {
|
func TestBranchMerge(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
Expect(`git merge --no-edit "test"`, "", nil)
|
Expect(`git merge --no-edit "test"`, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := NewBranchCommandsWithRunner(runner)
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Branch.Merge("test", MergeOpts{}))
|
assert.NoError(t, instance.Merge("test", MergeOpts{}))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandCheckout(t *testing.T) {
|
func TestBranchCheckout(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
@ -134,33 +140,32 @@ func TestGitCommandCheckout(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := NewBranchCommandsWithRunner(s.runner)
|
||||||
s.test(gitCmd.Branch.Checkout("test", CheckoutOptions{Force: s.force}))
|
s.test(instance.Checkout("test", CheckoutOptions{Force: s.force}))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandGetBranchGraph(t *testing.T) {
|
func TestBranchGetBranchGraph(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{
|
runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{
|
||||||
"log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--",
|
"log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--",
|
||||||
}, "", nil)
|
}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := NewBranchCommandsWithRunner(runner)
|
||||||
_, err := gitCmd.Branch.GetGraph("test")
|
_, err := instance.GetGraph("test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandGetAllBranchGraph(t *testing.T) {
|
func TestBranchGetAllBranchGraph(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{
|
runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{
|
||||||
"log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium",
|
"log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium",
|
||||||
}, "", nil)
|
}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := NewBranchCommandsWithRunner(runner)
|
||||||
cmdStr := gitCmd.UserConfig.Git.AllBranchesLogCmd
|
err := instance.AllBranchesLogCmdObj().Run()
|
||||||
_, err := gitCmd.Cmd.New(cmdStr).RunWithOutput()
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandCurrentBranchName(t *testing.T) {
|
func TestBranchCurrentBranchName(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
@ -214,8 +219,8 @@ func TestGitCommandCurrentBranchName(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := NewBranchCommandsWithRunner(s.runner)
|
||||||
s.test(gitCmd.Branch.CurrentBranchName())
|
s.test(instance.CurrentBranchName())
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,32 +4,35 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandRewordCommit(t *testing.T) {
|
func TestCommitRewordCommit(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"commit", "--allow-empty", "--amend", "--only", "-m", "test"}, "", nil)
|
ExpectGitArgs([]string{"commit", "--allow-empty", "--amend", "--only", "-m", "test"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := buildCommitCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Commit.RewordLastCommit("test"))
|
assert.NoError(t, instance.RewordLastCommit("test"))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandResetToCommit(t *testing.T) {
|
func TestCommitResetToCommit(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"reset", "--hard", "78976bc"}, "", nil)
|
ExpectGitArgs([]string{"reset", "--hard", "78976bc"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Commit.ResetToCommit("78976bc", "hard", []string{}))
|
instance := buildCommitCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
|
assert.NoError(t, instance.ResetToCommit("78976bc", "hard", []string{}))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandCommitObj(t *testing.T) {
|
func TestCommitCommitObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
message string
|
message string
|
||||||
flags string
|
configSignoff bool
|
||||||
|
configSkipHookPrefix string
|
||||||
expected string
|
expected string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,33 +40,55 @@ func TestGitCommandCommitObj(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testName: "Commit",
|
testName: "Commit",
|
||||||
message: "test",
|
message: "test",
|
||||||
flags: "",
|
configSignoff: false,
|
||||||
|
configSkipHookPrefix: "",
|
||||||
expected: `git commit -m "test"`,
|
expected: `git commit -m "test"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Commit with --no-verify flag",
|
testName: "Commit with --no-verify flag",
|
||||||
message: "test",
|
message: "WIP: test",
|
||||||
flags: "--no-verify",
|
configSignoff: false,
|
||||||
expected: `git commit --no-verify -m "test"`,
|
configSkipHookPrefix: "WIP",
|
||||||
|
expected: `git commit --no-verify -m "WIP: test"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Commit with multiline message",
|
testName: "Commit with multiline message",
|
||||||
message: "line1\nline2",
|
message: "line1\nline2",
|
||||||
flags: "",
|
configSignoff: false,
|
||||||
|
configSkipHookPrefix: "",
|
||||||
expected: `git commit -m "line1" -m "line2"`,
|
expected: `git commit -m "line1" -m "line2"`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "Commit with signoff",
|
||||||
|
message: "test",
|
||||||
|
configSignoff: true,
|
||||||
|
configSkipHookPrefix: "",
|
||||||
|
expected: `git commit --signoff -m "test"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Commit with signoff and no-verify",
|
||||||
|
message: "WIP: test",
|
||||||
|
configSignoff: true,
|
||||||
|
configSkipHookPrefix: "WIP",
|
||||||
|
expected: `git commit --no-verify --signoff -m "WIP: test"`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
userConfig := config.GetDefaultConfig()
|
||||||
cmdStr := gitCmd.Commit.CommitCmdObj(s.message, s.flags).ToString()
|
userConfig.Git.Commit.SignOff = s.configSignoff
|
||||||
|
userConfig.Git.SkipHookPrefix = s.configSkipHookPrefix
|
||||||
|
|
||||||
|
instance := buildCommitCommands(commonDeps{userConfig: userConfig})
|
||||||
|
|
||||||
|
cmdStr := instance.CommitCmdObj(s.message).ToString()
|
||||||
assert.Equal(t, s.expected, cmdStr)
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandCreateFixupCommit(t *testing.T) {
|
func TestCommitCreateFixupCommit(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
sha string
|
sha string
|
||||||
@ -85,14 +110,14 @@ func TestGitCommandCreateFixupCommit(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildCommitCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.Commit.CreateFixupCommit(s.sha))
|
s.test(instance.CreateFixupCommit(s.sha))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandShowCmdObj(t *testing.T) {
|
func TestCommitShowCmdObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
filterPath string
|
filterPath string
|
||||||
@ -123,9 +148,12 @@ func TestGitCommandShowCmdObj(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
userConfig := config.GetDefaultConfig()
|
||||||
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
cmdStr := gitCmd.Commit.ShowCmdObj("1234567890", s.filterPath).ToString()
|
|
||||||
|
instance := buildCommitCommands(commonDeps{userConfig: userConfig})
|
||||||
|
|
||||||
|
cmdStr := instance.ShowCmdObj("1234567890", s.filterPath).ToString()
|
||||||
assert.Equal(t, s.expected, cmdStr)
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
137
pkg/commands/deps_test.go
Normal file
137
pkg/commands/deps_test.go
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-errors/errors"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type commonDeps struct {
|
||||||
|
runner *oscommands.FakeCmdObjRunner
|
||||||
|
userConfig *config.UserConfig
|
||||||
|
gitConfig *git_config.FakeGitConfig
|
||||||
|
getenv func(string) string
|
||||||
|
removeFile func(string) error
|
||||||
|
dotGitDir string
|
||||||
|
common *common.Common
|
||||||
|
cmd *oscommands.CmdObjBuilder
|
||||||
|
}
|
||||||
|
|
||||||
|
func completeDeps(deps commonDeps) commonDeps {
|
||||||
|
if deps.runner == nil {
|
||||||
|
deps.runner = oscommands.NewFakeRunner(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.userConfig == nil {
|
||||||
|
deps.userConfig = config.GetDefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.gitConfig == nil {
|
||||||
|
deps.gitConfig = git_config.NewFakeGitConfig(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.getenv == nil {
|
||||||
|
deps.getenv = func(string) string { return "" }
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.removeFile == nil {
|
||||||
|
deps.removeFile = func(string) error { return errors.New("unexpected call to removeFile") }
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.dotGitDir == "" {
|
||||||
|
deps.dotGitDir = ".git"
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.common == nil {
|
||||||
|
deps.common = utils.NewDummyCommonWithUserConfig(deps.userConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
if deps.cmd == nil {
|
||||||
|
deps.cmd = oscommands.NewDummyCmdObjBuilder(deps.runner)
|
||||||
|
}
|
||||||
|
|
||||||
|
return deps
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildConfigCommands(deps commonDeps) *ConfigCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
common := utils.NewDummyCommonWithUserConfig(deps.userConfig)
|
||||||
|
|
||||||
|
return NewConfigCommands(common, deps.gitConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildOSCommand(deps commonDeps) *oscommands.OSCommand {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
|
||||||
|
return oscommands.NewDummyOSCommandWithDeps(oscommands.OSCommandDeps{
|
||||||
|
Common: deps.common,
|
||||||
|
GetenvFn: deps.getenv,
|
||||||
|
Cmd: deps.cmd,
|
||||||
|
RemoveFileFn: deps.removeFile,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildFileLoader(deps commonDeps) *loaders.FileLoader {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
|
||||||
|
configCommands := buildConfigCommands(deps)
|
||||||
|
|
||||||
|
return loaders.NewFileLoader(deps.common, deps.cmd, configCommands)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildSubmoduleCommands(deps commonDeps) *SubmoduleCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
|
||||||
|
return NewSubmoduleCommands(deps.common, deps.cmd, deps.dotGitDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildCommitCommands(deps commonDeps) *CommitCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
return NewCommitCommands(deps.common, deps.cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildWorkingTreeCommands(deps commonDeps) *WorkingTreeCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
osCommand := buildOSCommand(deps)
|
||||||
|
submoduleCommands := buildSubmoduleCommands(deps)
|
||||||
|
fileLoader := buildFileLoader(deps)
|
||||||
|
|
||||||
|
return NewWorkingTreeCommands(deps.common, deps.cmd, submoduleCommands, osCommand, fileLoader)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildStashCommands(deps commonDeps) *StashCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
osCommand := buildOSCommand(deps)
|
||||||
|
fileLoader := buildFileLoader(deps)
|
||||||
|
workingTreeCommands := buildWorkingTreeCommands(deps)
|
||||||
|
|
||||||
|
return NewStashCommands(deps.common, deps.cmd, osCommand, fileLoader, workingTreeCommands)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildRebaseCommands(deps commonDeps) *RebaseCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
configCommands := buildConfigCommands(deps)
|
||||||
|
osCommand := buildOSCommand(deps)
|
||||||
|
workingTreeCommands := buildWorkingTreeCommands(deps)
|
||||||
|
commitCommands := buildCommitCommands(deps)
|
||||||
|
|
||||||
|
return NewRebaseCommands(deps.common, deps.cmd, osCommand, commitCommands, workingTreeCommands, configCommands, deps.dotGitDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildSyncCommands(deps commonDeps) *SyncCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
|
||||||
|
return NewSyncCommands(deps.common, deps.cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildFileCommands(deps commonDeps) *FileCommands {
|
||||||
|
deps = completeDeps(deps)
|
||||||
|
configCommands := buildConfigCommands(deps)
|
||||||
|
osCommand := buildOSCommand(deps)
|
||||||
|
|
||||||
|
return NewFileCommands(deps.common, deps.cmd, configCommands, osCommand)
|
||||||
|
}
|
@ -51,7 +51,6 @@ func (c *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, e
|
|||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.config.GetCoreEditor()
|
editor = c.config.GetCoreEditor()
|
||||||
}
|
}
|
||||||
|
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
editor = c.os.Getenv("GIT_EDITOR")
|
editor = c.os.Getenv("GIT_EDITOR")
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -145,12 +146,18 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
userConfig := config.GetDefaultConfig()
|
||||||
gitCmd.UserConfig.OS.EditCommand = s.configEditCommand
|
userConfig.OS.EditCommand = s.configEditCommand
|
||||||
gitCmd.UserConfig.OS.EditCommandTemplate = s.configEditCommandTemplate
|
userConfig.OS.EditCommandTemplate = s.configEditCommandTemplate
|
||||||
gitCmd.OSCommand.GetenvFn = s.getenv
|
|
||||||
gitCmd.gitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses)
|
instance := buildFileCommands(commonDeps{
|
||||||
s.test(gitCmd.File.GetEditCmdStr(s.filename, 1))
|
runner: s.runner,
|
||||||
|
userConfig: userConfig,
|
||||||
|
gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses),
|
||||||
|
getenv: s.getenv,
|
||||||
|
})
|
||||||
|
|
||||||
|
s.test(instance.GetEditCmdStr(s.filename, 1))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandGetStatusFiles(t *testing.T) {
|
func TestFileGetStatusFiles(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner oscommands.ICmdObjRunner
|
runner oscommands.ICmdObjRunner
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandGetStashEntries(t *testing.T) {
|
func TestGetStashEntries(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
filterPath string
|
filterPath string
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package oscommands
|
package oscommands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,6 +12,34 @@ func NewDummyOSCommand() *OSCommand {
|
|||||||
return osCmd
|
return osCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OSCommandDeps struct {
|
||||||
|
Common *common.Common
|
||||||
|
Platform *Platform
|
||||||
|
GetenvFn func(string) string
|
||||||
|
RemoveFileFn func(string) error
|
||||||
|
Cmd *CmdObjBuilder
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDummyOSCommandWithDeps(deps OSCommandDeps) *OSCommand {
|
||||||
|
common := deps.Common
|
||||||
|
if common == nil {
|
||||||
|
common = utils.NewDummyCommon()
|
||||||
|
}
|
||||||
|
|
||||||
|
platform := deps.Platform
|
||||||
|
if platform == nil {
|
||||||
|
platform = dummyPlatform
|
||||||
|
}
|
||||||
|
|
||||||
|
return &OSCommand{
|
||||||
|
Common: common,
|
||||||
|
Platform: platform,
|
||||||
|
getenvFn: deps.GetenvFn,
|
||||||
|
removeFileFn: deps.RemoveFileFn,
|
||||||
|
guiIO: NewNullGuiIO(utils.NewDummyLog()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
|
func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
|
||||||
return &CmdObjBuilder{
|
return &CmdObjBuilder{
|
||||||
runner: runner,
|
runner: runner,
|
||||||
|
@ -20,10 +20,10 @@ import (
|
|||||||
type OSCommand struct {
|
type OSCommand struct {
|
||||||
*common.Common
|
*common.Common
|
||||||
Platform *Platform
|
Platform *Platform
|
||||||
GetenvFn func(string) string
|
getenvFn func(string) string
|
||||||
guiIO *guiIO
|
guiIO *guiIO
|
||||||
|
|
||||||
removeFile func(string) error
|
removeFileFn func(string) error
|
||||||
|
|
||||||
Cmd *CmdObjBuilder
|
Cmd *CmdObjBuilder
|
||||||
}
|
}
|
||||||
@ -42,8 +42,8 @@ func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCo
|
|||||||
c := &OSCommand{
|
c := &OSCommand{
|
||||||
Common: common,
|
Common: common,
|
||||||
Platform: platform,
|
Platform: platform,
|
||||||
GetenvFn: os.Getenv,
|
getenvFn: os.Getenv,
|
||||||
removeFile: os.RemoveAll,
|
removeFileFn: os.RemoveAll,
|
||||||
guiIO: guiIO,
|
guiIO: guiIO,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +59,6 @@ func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
|
|||||||
c.guiIO.logCommandFn(cmdStr, commandLine)
|
c.guiIO.logCommandFn(cmdStr, commandLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// To be used for testing only
|
|
||||||
func (c *OSCommand) SetRemoveFile(f func(string) error) {
|
|
||||||
c.removeFile = f
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileType tells us if the file is a file, directory or other
|
// FileType tells us if the file is a file, directory or other
|
||||||
func FileType(path string) string {
|
func FileType(path string) string {
|
||||||
fileInfo, err := os.Stat(path)
|
fileInfo, err := os.Stat(path)
|
||||||
@ -253,11 +248,11 @@ func (c *OSCommand) CopyToClipboard(str string) error {
|
|||||||
func (c *OSCommand) RemoveFile(path string) error {
|
func (c *OSCommand) RemoveFile(path string) error {
|
||||||
c.LogCommand(fmt.Sprintf("Deleting path '%s'", path), false)
|
c.LogCommand(fmt.Sprintf("Deleting path '%s'", path), false)
|
||||||
|
|
||||||
return c.removeFile(path)
|
return c.removeFileFn(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OSCommand) Getenv(key string) string {
|
func (c *OSCommand) Getenv(key string) string {
|
||||||
return c.GetenvFn(key)
|
return c.getenvFn(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTempDir() string {
|
func GetTempDir() string {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandRebaseBranch(t *testing.T) {
|
func TestRebaseRebaseBranch(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
arg string
|
arg string
|
||||||
@ -43,15 +43,15 @@ func TestGitCommandRebaseBranch(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildRebaseCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.Rebase.RebaseBranch(s.arg))
|
s.test(instance.RebaseBranch(s.arg))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestGitCommandSkipEditorCommand confirms that SkipEditorCommand injects
|
// TestRebaseSkipEditorCommand confirms that SkipEditorCommand injects
|
||||||
// environment variables that suppress an interactive editor
|
// environment variables that suppress an interactive editor
|
||||||
func TestGitCommandSkipEditorCommand(t *testing.T) {
|
func TestRebaseSkipEditorCommand(t *testing.T) {
|
||||||
commandStr := "git blah"
|
commandStr := "git blah"
|
||||||
runner := oscommands.NewFakeRunner(t).ExpectFunc(func(cmdObj oscommands.ICmdObj) (string, error) {
|
runner := oscommands.NewFakeRunner(t).ExpectFunc(func(cmdObj oscommands.ICmdObj) (string, error) {
|
||||||
assert.Equal(t, commandStr, cmdObj.ToString())
|
assert.Equal(t, commandStr, cmdObj.ToString())
|
||||||
@ -71,13 +71,13 @@ func TestGitCommandSkipEditorCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
})
|
})
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := buildRebaseCommands(commonDeps{runner: runner})
|
||||||
err := gitCmd.Rebase.runSkipEditorCommand(commandStr)
|
err := instance.runSkipEditorCommand(instance.cmd.New(commandStr))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandDiscardOldFileChanges(t *testing.T) {
|
func TestRebaseDiscardOldFileChanges(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
gitConfigMockResponses map[string]string
|
gitConfigMockResponses map[string]string
|
||||||
@ -136,9 +136,12 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildRebaseCommands(commonDeps{
|
||||||
gitCmd.gitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses)
|
runner: s.runner,
|
||||||
s.test(gitCmd.Rebase.DiscardOldFileChanges(s.commits, s.commitIndex, s.fileName))
|
gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses),
|
||||||
|
})
|
||||||
|
|
||||||
|
s.test(instance.DiscardOldFileChanges(s.commits, s.commitIndex, s.fileName))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,46 +4,47 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandStashDrop(t *testing.T) {
|
func TestStashDrop(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "", nil)
|
ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Stash.Drop(1))
|
assert.NoError(t, instance.Drop(1))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandStashApply(t *testing.T) {
|
func TestStashApply(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "apply", "stash@{1}"}, "", nil)
|
ExpectGitArgs([]string{"stash", "apply", "stash@{1}"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Stash.Apply(1))
|
assert.NoError(t, instance.Apply(1))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandStashPop(t *testing.T) {
|
func TestStashPop(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "pop", "stash@{1}"}, "", nil)
|
ExpectGitArgs([]string{"stash", "pop", "stash@{1}"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Stash.Pop(1))
|
assert.NoError(t, instance.Pop(1))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandStashSave(t *testing.T) {
|
func TestStashSave(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "save", "A stash message"}, "", nil)
|
ExpectGitArgs([]string{"stash", "save", "A stash message"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.Stash.Save("A stash message"))
|
assert.NoError(t, instance.Save("A stash message"))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandShowStashEntryCmdObj(t *testing.T) {
|
func TestStashStashEntryCmdObj(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
index int
|
index int
|
||||||
@ -68,9 +69,11 @@ func TestGitCommandShowStashEntryCmdObj(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommand()
|
userConfig := config.GetDefaultConfig()
|
||||||
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
cmdStr := gitCmd.Stash.ShowStashEntryCmdObj(s.index).ToString()
|
instance := buildStashCommands(commonDeps{userConfig: userConfig})
|
||||||
|
|
||||||
|
cmdStr := instance.ShowStashEntryCmdObj(s.index).ToString()
|
||||||
assert.Equal(t, s.expected, cmdStr)
|
assert.Equal(t, s.expected, cmdStr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandPush(t *testing.T) {
|
func TestSyncPush(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
opts PushOpts
|
opts PushOpts
|
||||||
@ -86,8 +86,8 @@ func TestGitCommandPush(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(oscommands.NewFakeRunner(t))
|
instance := buildSyncCommands(commonDeps{})
|
||||||
s.test(gitCmd.Sync.PushCmdObj(s.opts))
|
s.test(instance.PushCmdObj(s.opts))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,21 @@ import (
|
|||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitCommandStageFile(t *testing.T) {
|
func TestWorkingTreeStageFile(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectArgs([]string{"git", "add", "--", "test.txt"}, "", nil)
|
ExpectArgs([]string{"git", "add", "--", "test.txt"}, "", nil)
|
||||||
gitCmd := NewDummyGitCommandWithRunner(runner)
|
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.WorkingTree.StageFile("test.txt"))
|
instance := buildWorkingTreeCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
|
assert.NoError(t, instance.StageFile("test.txt"))
|
||||||
runner.CheckForMissingCalls()
|
runner.CheckForMissingCalls()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandUnstageFile(t *testing.T) {
|
func TestWorkingTreeUnstageFile(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
reset bool
|
reset bool
|
||||||
@ -52,8 +54,8 @@ func TestGitCommandUnstageFile(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.UnStageFile([]string{"test.txt"}, s.reset))
|
s.test(instance.UnStageFile([]string{"test.txt"}, s.reset))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +63,7 @@ func TestGitCommandUnstageFile(t *testing.T) {
|
|||||||
// these tests don't cover everything, in part because we already have an integration
|
// these tests don't cover everything, in part because we already have an integration
|
||||||
// test which does cover everything. I don't want to unnecessarily assert on the 'how'
|
// test which does cover everything. I don't want to unnecessarily assert on the 'how'
|
||||||
// when the 'what' is what matters
|
// when the 'what' is what matters
|
||||||
func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
file *models.File
|
file *models.File
|
||||||
@ -180,9 +182,8 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, removeFile: s.removeFile})
|
||||||
gitCmd.OSCommand.SetRemoveFile(s.removeFile)
|
err := instance.DiscardAllFileChanges(s.file)
|
||||||
err := gitCmd.WorkingTree.DiscardAllFileChanges(s.file)
|
|
||||||
|
|
||||||
if s.expectedError == "" {
|
if s.expectedError == "" {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@ -194,7 +195,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandDiff(t *testing.T) {
|
func TestWorkingTreeDiff(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
file *models.File
|
file *models.File
|
||||||
@ -296,16 +297,18 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
userConfig := config.GetDefaultConfig()
|
||||||
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
result := gitCmd.WorkingTree.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace)
|
|
||||||
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig})
|
||||||
|
result := instance.WorktreeFileDiff(s.file, s.plain, s.cached, s.ignoreWhitespace)
|
||||||
assert.Equal(t, expectedResult, result)
|
assert.Equal(t, expectedResult, result)
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandShowFileDiff(t *testing.T) {
|
func TestWorkingTreeShowFileDiff(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
from string
|
from string
|
||||||
@ -343,9 +346,12 @@ func TestGitCommandShowFileDiff(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
userConfig := config.GetDefaultConfig()
|
||||||
gitCmd.UserConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
result, err := gitCmd.WorkingTree.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain)
|
|
||||||
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner, userConfig: userConfig})
|
||||||
|
|
||||||
|
result, err := instance.ShowFileDiff(s.from, s.to, s.reverse, "test.txt", s.plain)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expectedResult, result)
|
assert.Equal(t, expectedResult, result)
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
@ -353,7 +359,7 @@ func TestGitCommandShowFileDiff(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandCheckoutFile(t *testing.T) {
|
func TestWorkingTreeCheckoutFile(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
commitSha string
|
commitSha string
|
||||||
@ -387,14 +393,15 @@ func TestGitCommandCheckoutFile(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.CheckoutFile(s.commitSha, s.fileName))
|
|
||||||
|
s.test(instance.CheckoutFile(s.commitSha, s.fileName))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandApplyPatch(t *testing.T) {
|
func TestWorkingTreeApplyPatch(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
@ -439,14 +446,14 @@ func TestGitCommandApplyPatch(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.ApplyPatch("test", "cached"))
|
s.test(instance.ApplyPatch("test", "cached"))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
func TestWorkingTreeDiscardUnstagedFileChanges(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
file *models.File
|
file *models.File
|
||||||
@ -468,14 +475,14 @@ func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.DiscardUnstagedFileChanges(s.file))
|
s.test(instance.DiscardUnstagedFileChanges(s.file))
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandDiscardAnyUnstagedFileChanges(t *testing.T) {
|
func TestWorkingTreeDiscardAnyUnstagedFileChanges(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
@ -495,14 +502,14 @@ func TestGitCommandDiscardAnyUnstagedFileChanges(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.DiscardAnyUnstagedFileChanges())
|
s.test(instance.DiscardAnyUnstagedFileChanges())
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
|
func TestWorkingTreeRemoveUntrackedFiles(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
runner *oscommands.FakeCmdObjRunner
|
runner *oscommands.FakeCmdObjRunner
|
||||||
@ -522,14 +529,14 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.RemoveUntrackedFiles())
|
s.test(instance.RemoveUntrackedFiles())
|
||||||
s.runner.CheckForMissingCalls()
|
s.runner.CheckForMissingCalls()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCommandResetHard(t *testing.T) {
|
func TestWorkingTreeResetHard(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
ref string
|
ref string
|
||||||
@ -551,8 +558,8 @@ func TestGitCommandResetHard(t *testing.T) {
|
|||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
gitCmd := NewDummyGitCommandWithRunner(s.runner)
|
instance := buildWorkingTreeCommands(commonDeps{runner: s.runner})
|
||||||
s.test(gitCmd.WorkingTree.ResetHard(s.ref))
|
s.test(instance.ResetHard(s.ref))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,7 @@ func (gui *Gui) handleCreateRecentReposMenu() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleShowAllBranchLogs() error {
|
func (gui *Gui) handleShowAllBranchLogs() error {
|
||||||
cmdObj := gui.OSCommand.Cmd.New(
|
cmdObj := gui.GitCommand.Branch.AllBranchesLogCmdObj()
|
||||||
gui.UserConfig.Git.AllBranchesLogCmd,
|
|
||||||
)
|
|
||||||
task := NewRunPtyTask(cmdObj.GetCmd())
|
task := NewRunPtyTask(cmdObj.GetCmd())
|
||||||
|
|
||||||
return gui.refreshMainViews(refreshMainOpts{
|
return gui.refreshMainViews(refreshMainOpts{
|
||||||
|
@ -26,6 +26,15 @@ func NewDummyCommon() *common.Common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewDummyCommonWithUserConfig(userConfig *config.UserConfig) *common.Common {
|
||||||
|
tr := i18n.EnglishTranslationSet()
|
||||||
|
return &common.Common{
|
||||||
|
Log: NewDummyLog(),
|
||||||
|
Tr: &tr,
|
||||||
|
UserConfig: userConfig,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewDummyGitConfig() git_config.IGitConfig {
|
func NewDummyGitConfig() git_config.IGitConfig {
|
||||||
return git_config.NewFakeGitConfig(map[string]string{})
|
return git_config.NewFakeGitConfig(map[string]string{})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user