diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/branches.go | 4 | ||||
-rw-r--r-- | pkg/commands/branches_test.go | 55 | ||||
-rw-r--r-- | pkg/commands/commits_test.go | 92 | ||||
-rw-r--r-- | pkg/commands/deps_test.go | 137 | ||||
-rw-r--r-- | pkg/commands/files.go | 1 | ||||
-rw-r--r-- | pkg/commands/files_test.go | 19 | ||||
-rw-r--r-- | pkg/commands/loaders/files_test.go | 2 | ||||
-rw-r--r-- | pkg/commands/loaders/stash_test.go | 2 | ||||
-rw-r--r-- | pkg/commands/oscommands/dummies.go | 29 | ||||
-rw-r--r-- | pkg/commands/oscommands/os.go | 23 | ||||
-rw-r--r-- | pkg/commands/rebasing_test.go | 25 | ||||
-rw-r--r-- | pkg/commands/stash_entries_test.go | 35 | ||||
-rw-r--r-- | pkg/commands/sync_test.go | 6 | ||||
-rw-r--r-- | pkg/commands/working_tree_test.go | 79 | ||||
-rw-r--r-- | pkg/gui/recent_repos_panel.go | 4 | ||||
-rw-r--r-- | pkg/utils/dummies.go | 9 |
16 files changed, 373 insertions, 149 deletions
diff --git a/pkg/commands/branches.go b/pkg/commands/branches.go index 2980ae722..c9cd444ae 100644 --- a/pkg/commands/branches.go +++ b/pkg/commands/branches.go @@ -174,3 +174,7 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error { return self.cmd.New(command).Run() } + +func (self *BranchCommands) AllBranchesLogCmdObj() oscommands.ICmdObj { + return self.cmd.New(self.UserConfig.Git.AllBranchesLogCmd).DontLog() +} diff --git a/pkg/commands/branches_test.go b/pkg/commands/branches_test.go index 6a2918a6b..102e5f661 100644 --- a/pkg/commands/branches_test.go +++ b/pkg/commands/branches_test.go @@ -5,10 +5,16 @@ import ( "github.com/go-errors/errors" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/utils" "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 { testName string runner *oscommands.FakeCmdObjRunner @@ -41,8 +47,8 @@ func TestGitCommandGetCommitDifferences(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - pushables, pullables := gitCmd.Branch.GetCommitDifferences("HEAD", "@{u}") + instance := NewBranchCommandsWithRunner(s.runner) + pushables, pullables := instance.GetCommitDifferences("HEAD", "@{u}") assert.EqualValues(t, s.expectedPushables, pushables) assert.EqualValues(t, s.expectedPullables, pullables) 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). 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() } -func TestGitCommandDeleteBranch(t *testing.T) { +func TestBranchDeleteBranch(t *testing.T) { type scenario struct { testName string force bool @@ -88,24 +94,24 @@ func TestGitCommandDeleteBranch(t *testing.T) { for _, s := range scenarios { 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() }) } } -func TestGitCommandMerge(t *testing.T) { +func TestBranchMerge(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandCheckout(t *testing.T) { +func TestBranchCheckout(t *testing.T) { type scenario struct { testName string runner *oscommands.FakeCmdObjRunner @@ -134,33 +140,32 @@ func TestGitCommandCheckout(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - s.test(gitCmd.Branch.Checkout("test", CheckoutOptions{Force: s.force})) + instance := NewBranchCommandsWithRunner(s.runner) + s.test(instance.Checkout("test", CheckoutOptions{Force: s.force})) s.runner.CheckForMissingCalls() }) } } -func TestGitCommandGetBranchGraph(t *testing.T) { +func TestBranchGetBranchGraph(t *testing.T) { runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{ "log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--", }, "", nil) - gitCmd := NewDummyGitCommandWithRunner(runner) - _, err := gitCmd.Branch.GetGraph("test") + instance := NewBranchCommandsWithRunner(runner) + _, err := instance.GetGraph("test") assert.NoError(t, err) } -func TestGitCommandGetAllBranchGraph(t *testing.T) { +func TestBranchGetAllBranchGraph(t *testing.T) { runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{ "log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", }, "", nil) - gitCmd := NewDummyGitCommandWithRunner(runner) - cmdStr := gitCmd.UserConfig.Git.AllBranchesLogCmd - _, err := gitCmd.Cmd.New(cmdStr).RunWithOutput() + instance := NewBranchCommandsWithRunner(runner) + err := instance.AllBranchesLogCmdObj().Run() assert.NoError(t, err) } -func TestGitCommandCurrentBranchName(t *testing.T) { +func TestBranchCurrentBranchName(t *testing.T) { type scenario struct { testName string runner *oscommands.FakeCmdObjRunner @@ -214,8 +219,8 @@ func TestGitCommandCurrentBranchName(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - s.test(gitCmd.Branch.CurrentBranchName()) + instance := NewBranchCommandsWithRunner(s.runner) + s.test(instance.CurrentBranchName()) s.runner.CheckForMissingCalls() }) } diff --git a/pkg/commands/commits_test.go b/pkg/commands/commits_test.go index c994a04f5..b8a5cebc3 100644 --- a/pkg/commands/commits_test.go +++ b/pkg/commands/commits_test.go @@ -4,66 +4,91 @@ import ( "testing" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/stretchr/testify/assert" ) -func TestGitCommandRewordCommit(t *testing.T) { +func TestCommitRewordCommit(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandResetToCommit(t *testing.T) { +func TestCommitResetToCommit(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandCommitObj(t *testing.T) { +func TestCommitCommitObj(t *testing.T) { type scenario struct { - testName string - message string - flags string - expected string + testName string + message string + configSignoff bool + configSkipHookPrefix string + expected string } scenarios := []scenario{ { - testName: "Commit", - message: "test", - flags: "", - expected: `git commit -m "test"`, + testName: "Commit", + message: "test", + configSignoff: false, + configSkipHookPrefix: "", + expected: `git commit -m "test"`, + }, + { + testName: "Commit with --no-verify flag", + message: "WIP: test", + configSignoff: false, + configSkipHookPrefix: "WIP", + expected: `git commit --no-verify -m "WIP: test"`, + }, + { + testName: "Commit with multiline message", + message: "line1\nline2", + configSignoff: false, + configSkipHookPrefix: "", + expected: `git commit -m "line1" -m "line2"`, }, { - testName: "Commit with --no-verify flag", - message: "test", - flags: "--no-verify", - expected: `git commit --no-verify -m "test"`, + testName: "Commit with signoff", + message: "test", + configSignoff: true, + configSkipHookPrefix: "", + expected: `git commit --signoff -m "test"`, }, { - testName: "Commit with multiline message", - message: "line1\nline2", - flags: "", - expected: `git commit -m "line1" -m "line2"`, + 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 { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommand() - cmdStr := gitCmd.Commit.CommitCmdObj(s.message, s.flags).ToString() + userConfig := config.GetDefaultConfig() + 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) }) } } -func TestGitCommandCreateFixupCommit(t *testing.T) { +func TestCommitCreateFixupCommit(t *testing.T) { type scenario struct { testName string sha string @@ -85,14 +110,14 @@ func TestGitCommandCreateFixupCommit(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - s.test(gitCmd.Commit.CreateFixupCommit(s.sha)) + instance := buildCommitCommands(commonDeps{runner: s.runner}) + s.test(instance.CreateFixupCommit(s.sha)) s.runner.CheckForMissingCalls() }) } } -func TestGitCommandShowCmdObj(t *testing.T) { +func TestCommitShowCmdObj(t *testing.T) { type scenario struct { testName string filterPath string @@ -123,9 +148,12 @@ func TestGitCommandShowCmdObj(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommand() - gitCmd.UserConfig.Git.DiffContextSize = s.contextSize - cmdStr := gitCmd.Commit.ShowCmdObj("1234567890", s.filterPath).ToString() + userConfig := config.GetDefaultConfig() + userConfig.Git.DiffContextSize = s.contextSize + + instance := buildCommitCommands(commonDeps{userConfig: userConfig}) + + cmdStr := instance.ShowCmdObj("1234567890", s.filterPath).ToString() assert.Equal(t, s.expected, cmdStr) }) } diff --git a/pkg/commands/deps_test.go b/pkg/commands/deps_test.go new file mode 100644 index 000000000..59eeb8a0e --- /dev/null +++ b/pkg/commands/deps_test.go @@ -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) +} diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 9e17e60e0..5b4f7fb1f 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -51,7 +51,6 @@ func (c *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, e if editor == "" { editor = c.config.GetCoreEditor() } - if editor == "" { editor = c.os.Getenv("GIT_EDITOR") } diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index 6f03125cb..ed8a41783 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-errors/errors" "github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/stretchr/testify/assert" ) @@ -145,12 +146,18 @@ func TestEditFileCmdStr(t *testing.T) { } for _, s := range scenarios { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - gitCmd.UserConfig.OS.EditCommand = s.configEditCommand - gitCmd.UserConfig.OS.EditCommandTemplate = s.configEditCommandTemplate - gitCmd.OSCommand.GetenvFn = s.getenv - gitCmd.gitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses) - s.test(gitCmd.File.GetEditCmdStr(s.filename, 1)) + userConfig := config.GetDefaultConfig() + userConfig.OS.EditCommand = s.configEditCommand + userConfig.OS.EditCommandTemplate = s.configEditCommandTemplate + + instance := buildFileCommands(commonDeps{ + runner: s.runner, + userConfig: userConfig, + gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses), + getenv: s.getenv, + }) + + s.test(instance.GetEditCmdStr(s.filename, 1)) s.runner.CheckForMissingCalls() } } diff --git a/pkg/commands/loaders/files_test.go b/pkg/commands/loaders/files_test.go index 1613290bb..2f1b12704 100644 --- a/pkg/commands/loaders/files_test.go +++ b/pkg/commands/loaders/files_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGitCommandGetStatusFiles(t *testing.T) { +func TestFileGetStatusFiles(t *testing.T) { type scenario struct { testName string runner oscommands.ICmdObjRunner diff --git a/pkg/commands/loaders/stash_test.go b/pkg/commands/loaders/stash_test.go index d7b313fbe..31c83792f 100644 --- a/pkg/commands/loaders/stash_test.go +++ b/pkg/commands/loaders/stash_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGitCommandGetStashEntries(t *testing.T) { +func TestGetStashEntries(t *testing.T) { type scenario struct { testName string filterPath string diff --git a/pkg/commands/oscommands/dummies.go b/pkg/commands/oscommands/dummies.go index 3d8b1a833..158e9a9c1 100644 --- a/pkg/commands/oscommands/dummies.go +++ b/pkg/commands/oscommands/dummies.go @@ -1,6 +1,7 @@ package oscommands import ( + "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -11,6 +12,34 @@ func NewDummyOSCommand() *OSCommand { 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 { return &CmdObjBuilder{ runner: runner, diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index f8ad29c1f..b328345e9 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -20,10 +20,10 @@ import ( type OSCommand struct { *common.Common Platform *Platform - GetenvFn func(string) string + getenvFn func(string) string guiIO *guiIO - removeFile func(string) error + removeFileFn func(string) error Cmd *CmdObjBuilder } @@ -40,11 +40,11 @@ type Platform struct { // NewOSCommand os command runner func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCommand { c := &OSCommand{ - Common: common, - Platform: platform, - GetenvFn: os.Getenv, - removeFile: os.RemoveAll, - guiIO: guiIO, + Common: common, + Platform: platform, + getenvFn: os.Getenv, + removeFileFn: os.RemoveAll, + guiIO: guiIO, } runner := &cmdObjRunner{log: common.Log, guiIO: guiIO} @@ -59,11 +59,6 @@ func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) { 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 func FileType(path string) string { fileInfo, err := os.Stat(path) @@ -253,11 +248,11 @@ func (c *OSCommand) CopyToClipboard(str string) error { func (c *OSCommand) RemoveFile(path string) error { c.LogCommand(fmt.Sprintf("Deleting path '%s'", path), false) - return c.removeFile(path) + return c.removeFileFn(path) } func (c *OSCommand) Getenv(key string) string { - return c.GetenvFn(key) + return c.getenvFn(key) } func GetTempDir() string { diff --git a/pkg/commands/rebasing_test.go b/pkg/commands/rebasing_test.go index 410b25f22..582da91b7 100644 --- a/pkg/commands/rebasing_test.go +++ b/pkg/commands/rebasing_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGitCommandRebaseBranch(t *testing.T) { +func TestRebaseRebaseBranch(t *testing.T) { type scenario struct { testName string arg string @@ -43,15 +43,15 @@ func TestGitCommandRebaseBranch(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - s.test(gitCmd.Rebase.RebaseBranch(s.arg)) + instance := buildRebaseCommands(commonDeps{runner: s.runner}) + s.test(instance.RebaseBranch(s.arg)) }) } } -// TestGitCommandSkipEditorCommand confirms that SkipEditorCommand injects +// TestRebaseSkipEditorCommand confirms that SkipEditorCommand injects // environment variables that suppress an interactive editor -func TestGitCommandSkipEditorCommand(t *testing.T) { +func TestRebaseSkipEditorCommand(t *testing.T) { commandStr := "git blah" runner := oscommands.NewFakeRunner(t).ExpectFunc(func(cmdObj oscommands.ICmdObj) (string, error) { assert.Equal(t, commandStr, cmdObj.ToString()) @@ -71,13 +71,13 @@ func TestGitCommandSkipEditorCommand(t *testing.T) { } return "", nil }) - gitCmd := NewDummyGitCommandWithRunner(runner) - err := gitCmd.Rebase.runSkipEditorCommand(commandStr) + instance := buildRebaseCommands(commonDeps{runner: runner}) + err := instance.runSkipEditorCommand(instance.cmd.New(commandStr)) assert.NoError(t, err) runner.CheckForMissingCalls() } -func TestGitCommandDiscardOldFileChanges(t *testing.T) { +func TestRebaseDiscardOldFileChanges(t *testing.T) { type scenario struct { testName string gitConfigMockResponses map[string]string @@ -136,9 +136,12 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - gitCmd.gitConfig = git_config.NewFakeGitConfig(s.gitConfigMockResponses) - s.test(gitCmd.Rebase.DiscardOldFileChanges(s.commits, s.commitIndex, s.fileName)) + instance := buildRebaseCommands(commonDeps{ + runner: s.runner, + gitConfig: git_config.NewFakeGitConfig(s.gitConfigMockResponses), + }) + + s.test(instance.DiscardOldFileChanges(s.commits, s.commitIndex, s.fileName)) s.runner.CheckForMissingCalls() }) } diff --git a/pkg/commands/stash_entries_test.go b/pkg/commands/stash_entries_test.go index f179c3fb1..9f51ea3f3 100644 --- a/pkg/commands/stash_entries_test.go +++ b/pkg/commands/stash_entries_test.go @@ -4,46 +4,47 @@ import ( "testing" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/stretchr/testify/assert" ) -func TestGitCommandStashDrop(t *testing.T) { +func TestStashDrop(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandStashApply(t *testing.T) { +func TestStashApply(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandStashPop(t *testing.T) { +func TestStashPop(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandStashSave(t *testing.T) { +func TestStashSave(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandShowStashEntryCmdObj(t *testing.T) { +func TestStashStashEntryCmdObj(t *testing.T) { type scenario struct { testName string index int @@ -68,9 +69,11 @@ func TestGitCommandShowStashEntryCmdObj(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommand() - gitCmd.UserConfig.Git.DiffContextSize = s.contextSize - cmdStr := gitCmd.Stash.ShowStashEntryCmdObj(s.index).ToString() + userConfig := config.GetDefaultConfig() + userConfig.Git.DiffContextSize = s.contextSize + instance := buildStashCommands(commonDeps{userConfig: userConfig}) + + cmdStr := instance.ShowStashEntryCmdObj(s.index).ToString() assert.Equal(t, s.expected, cmdStr) }) } diff --git a/pkg/commands/sync_test.go b/pkg/commands/sync_test.go index 13fb77523..af9942aa0 100644 --- a/pkg/commands/sync_test.go +++ b/pkg/commands/sync_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGitCommandPush(t *testing.T) { +func TestSyncPush(t *testing.T) { type scenario struct { testName string opts PushOpts @@ -86,8 +86,8 @@ func TestGitCommandPush(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(oscommands.NewFakeRunner(t)) - s.test(gitCmd.Sync.PushCmdObj(s.opts)) + instance := buildSyncCommands(commonDeps{}) + s.test(instance.PushCmdObj(s.opts)) }) } } diff --git a/pkg/commands/working_tree_test.go b/pkg/commands/working_tree_test.go index 15b552cd5..8e773314d 100644 --- a/pkg/commands/working_tree_test.go +++ b/pkg/commands/working_tree_test.go @@ -9,19 +9,21 @@ import ( "github.com/go-errors/errors" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/stretchr/testify/assert" ) -func TestGitCommandStageFile(t *testing.T) { +func TestWorkingTreeStageFile(t *testing.T) { runner := oscommands.NewFakeRunner(t). 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() } -func TestGitCommandUnstageFile(t *testing.T) { +func TestWorkingTreeUnstageFile(t *testing.T) { type scenario struct { testName string reset bool @@ -52,8 +54,8 @@ func TestGitCommandUnstageFile(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommandWithRunner(s.runner) - s.test(gitCmd.WorkingTree.UnStageFile([]string{"test.txt"}, s.reset)) + instance := buildWorkingTreeCommands(commonDeps{runner: s.runner}) + s.test(instance.UnStageFile([]string{"test.txt"} |