diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-18 21:26:21 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-18 22:01:09 +1100 |
commit | 3e80a9e886007e11cc774b74a32959625e102750 (patch) | |
tree | 0388789b4929785542afcb9f3a6691db0873180f /pkg | |
parent | 9706416a4171b9fce72d404ef38e2988b894c554 (diff) |
refactor to group up more commonly used git command stuff
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git.go | 39 | ||||
-rw-r--r-- | pkg/commands/git_commands/branch.go | 13 | ||||
-rw-r--r-- | pkg/commands/git_commands/branch_test.go | 22 | ||||
-rw-r--r-- | pkg/commands/git_commands/commit.go | 13 | ||||
-rw-r--r-- | pkg/commands/git_commands/common.go | 34 | ||||
-rw-r--r-- | pkg/commands/git_commands/custom.go | 17 | ||||
-rw-r--r-- | pkg/commands/git_commands/deps_test.go | 131 | ||||
-rw-r--r-- | pkg/commands/git_commands/file.go | 24 | ||||
-rw-r--r-- | pkg/commands/git_commands/flow.go | 14 | ||||
-rw-r--r-- | pkg/commands/git_commands/patch.go | 38 | ||||
-rw-r--r-- | pkg/commands/git_commands/rebase.go | 28 | ||||
-rw-r--r-- | pkg/commands/git_commands/remote.go | 15 | ||||
-rw-r--r-- | pkg/commands/git_commands/stash.go | 16 | ||||
-rw-r--r-- | pkg/commands/git_commands/status.go | 23 | ||||
-rw-r--r-- | pkg/commands/git_commands/submodule.go | 12 | ||||
-rw-r--r-- | pkg/commands/git_commands/sync.go | 13 | ||||
-rw-r--r-- | pkg/commands/git_commands/tag.go | 12 | ||||
-rw-r--r-- | pkg/commands/git_commands/working_tree.go | 24 |
18 files changed, 191 insertions, 297 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 7338cd0f1..b75410322 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -92,32 +92,27 @@ func NewGitCommandAux( // This is admittedly messy, but allows us to test each command struct in isolation, // and allows for better namespacing when compared to having every method living // on the one struct. + // common ones are: cmn, osCommand, dotGitDir, configCommands configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo) - statusCommands := git_commands.NewStatusCommands(cmn, osCommand, repo, dotGitDir) + gitCommon := git_commands.NewGitCommon(cmn, cmd, osCommand, dotGitDir, repo, configCommands) + + statusCommands := git_commands.NewStatusCommands(gitCommon) fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands) - flowCommands := git_commands.NewFlowCommands(cmn, cmd, configCommands) - remoteCommands := git_commands.NewRemoteCommands(cmn, cmd) - branchCommands := git_commands.NewBranchCommands(cmn, cmd) - syncCommands := git_commands.NewSyncCommands(cmn, cmd) - tagCommands := git_commands.NewTagCommands(cmn, cmd) - commitCommands := git_commands.NewCommitCommands(cmn, cmd) - customCommands := git_commands.NewCustomCommands(cmn, cmd) - fileCommands := git_commands.NewFileCommands(cmn, cmd, configCommands, osCommand) - submoduleCommands := git_commands.NewSubmoduleCommands(cmn, cmd, dotGitDir) - workingTreeCommands := git_commands.NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader) - rebaseCommands := git_commands.NewRebaseCommands( - cmn, - cmd, - osCommand, - commitCommands, - workingTreeCommands, - configCommands, - dotGitDir, - ) - stashCommands := git_commands.NewStashCommands(cmn, cmd, osCommand, fileLoader, workingTreeCommands) + flowCommands := git_commands.NewFlowCommands(gitCommon) + remoteCommands := git_commands.NewRemoteCommands(gitCommon) + branchCommands := git_commands.NewBranchCommands(gitCommon) + syncCommands := git_commands.NewSyncCommands(gitCommon) + tagCommands := git_commands.NewTagCommands(gitCommon) + commitCommands := git_commands.NewCommitCommands(gitCommon) + customCommands := git_commands.NewCustomCommands(gitCommon) + fileCommands := git_commands.NewFileCommands(gitCommon) + submoduleCommands := git_commands.NewSubmoduleCommands(gitCommon) + workingTreeCommands := git_commands.NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader) + rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands) + stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands) // TODO: have patch manager take workingTreeCommands in its entirety patchManager := patch.NewPatchManager(cmn.Log, workingTreeCommands.ApplyPatch, workingTreeCommands.ShowFileDiff) - patchCommands := git_commands.NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager) + patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchManager) return &GitCommand{ Branch: branchCommands, diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 59af77612..f6b084c9f 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -17,18 +16,12 @@ import ( const CurrentBranchNameRegex = `(?m)^\*.*?([^ ]*?)\)?$` type BranchCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder + *GitCommon } -func NewBranchCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, -) *BranchCommands { +func NewBranchCommands(gitCommon *GitCommon) *BranchCommands { return &BranchCommands{ - Common: common, - cmd: cmd, + GitCommon: gitCommon, } } diff --git a/pkg/commands/git_commands/branch_test.go b/pkg/commands/git_commands/branch_test.go index 552165695..757a8a83d 100644 --- a/pkg/commands/git_commands/branch_test.go +++ b/pkg/commands/git_commands/branch_test.go @@ -5,15 +5,9 @@ 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 NewBranchCommandsWithRunner(runner *oscommands.FakeCmdObjRunner) *BranchCommands { - builder := oscommands.NewDummyCmdObjBuilder(runner) - return NewBranchCommands(utils.NewDummyCommon(), builder) -} - func TestBranchGetCommitDifferences(t *testing.T) { type scenario struct { testName string @@ -48,7 +42,7 @@ func TestBranchGetCommitDifferences(t *testing.T) { for _, s := range scenarios { s := s t.Run(s.testName, func(t *testing.T) { - instance := NewBranchCommandsWithRunner(s.runner) + instance := buildBranchCommands(commonDeps{runner: s.runner}) pushables, pullables := instance.GetCommitDifferences("HEAD", "@{u}") assert.EqualValues(t, s.expectedPushables, pushables) assert.EqualValues(t, s.expectedPullables, pullables) @@ -60,7 +54,7 @@ func TestBranchGetCommitDifferences(t *testing.T) { func TestBranchNewBranch(t *testing.T) { runner := oscommands.NewFakeRunner(t). Expect(`git checkout -b "test" "master"`, "", nil) - instance := NewBranchCommandsWithRunner(runner) + instance := buildBranchCommands(commonDeps{runner: runner}) assert.NoError(t, instance.New("test", "master")) runner.CheckForMissingCalls() @@ -96,7 +90,7 @@ func TestBranchDeleteBranch(t *testing.T) { for _, s := range scenarios { s := s t.Run(s.testName, func(t *testing.T) { - instance := NewBranchCommandsWithRunner(s.runner) + instance := buildBranchCommands(commonDeps{runner: s.runner}) s.test(instance.Delete("test", s.force)) s.runner.CheckForMissingCalls() @@ -107,7 +101,7 @@ func TestBranchDeleteBranch(t *testing.T) { func TestBranchMerge(t *testing.T) { runner := oscommands.NewFakeRunner(t). Expect(`git merge --no-edit "test"`, "", nil) - instance := NewBranchCommandsWithRunner(runner) + instance := buildBranchCommands(commonDeps{runner: runner}) assert.NoError(t, instance.Merge("test", MergeOpts{})) runner.CheckForMissingCalls() @@ -143,7 +137,7 @@ func TestBranchCheckout(t *testing.T) { for _, s := range scenarios { s := s t.Run(s.testName, func(t *testing.T) { - instance := NewBranchCommandsWithRunner(s.runner) + instance := buildBranchCommands(commonDeps{runner: s.runner}) s.test(instance.Checkout("test", CheckoutOptions{Force: s.force})) s.runner.CheckForMissingCalls() }) @@ -154,7 +148,7 @@ func TestBranchGetBranchGraph(t *testing.T) { runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{ "log", "--graph", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "test", "--", }, "", nil) - instance := NewBranchCommandsWithRunner(runner) + instance := buildBranchCommands(commonDeps{runner: runner}) _, err := instance.GetGraph("test") assert.NoError(t, err) } @@ -163,7 +157,7 @@ func TestBranchGetAllBranchGraph(t *testing.T) { runner := oscommands.NewFakeRunner(t).ExpectGitArgs([]string{ "log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", }, "", nil) - instance := NewBranchCommandsWithRunner(runner) + instance := buildBranchCommands(commonDeps{runner: runner}) err := instance.AllBranchesLogCmdObj().Run() assert.NoError(t, err) } @@ -223,7 +217,7 @@ func TestBranchCurrentBranchName(t *testing.T) { for _, s := range scenarios { s := s t.Run(s.testName, func(t *testing.T) { - instance := NewBranchCommandsWithRunner(s.runner) + instance := buildBranchCommands(commonDeps{runner: s.runner}) s.test(instance.CurrentBranchName()) s.runner.CheckForMissingCalls() }) diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 866634013..2858c100a 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -5,22 +5,15 @@ import ( "strings" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" ) type CommitCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder + *GitCommon } -func NewCommitCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, -) *CommitCommands { +func NewCommitCommands(gitCommon *GitCommon) *CommitCommands { return &CommitCommands{ - Common: common, - cmd: cmd, + GitCommon: gitCommon, } } diff --git a/pkg/commands/git_commands/common.go b/pkg/commands/git_commands/common.go new file mode 100644 index 000000000..a045be75a --- /dev/null +++ b/pkg/commands/git_commands/common.go @@ -0,0 +1,34 @@ +package git_commands + +import ( + gogit "github.com/jesseduffield/go-git/v5" + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/common" +) + +type GitCommon struct { + *common.Common + cmd oscommands.ICmdObjBuilder + os *oscommands.OSCommand + dotGitDir string + repo *gogit.Repository + config *ConfigCommands +} + +func NewGitCommon( + cmn *common.Common, + cmd oscommands.ICmdObjBuilder, + osCommand *oscommands.OSCommand, + dotGitDir string, + repo *gogit.Repository, + config *ConfigCommands, +) *GitCommon { + return &GitCommon{ + Common: cmn, + cmd: cmd, + os: osCommand, + dotGitDir: dotGitDir, + repo: repo, + config: config, + } +} diff --git a/pkg/commands/git_commands/custom.go b/pkg/commands/git_commands/custom.go index 27a0bf93f..6dff6e771 100644 --- a/pkg/commands/git_commands/custom.go +++ b/pkg/commands/git_commands/custom.go @@ -1,23 +1,12 @@ package git_commands -import ( - "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" -) - type CustomCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder + *GitCommon } -func NewCustomCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, -) *CustomCommands { +func NewCustomCommands(gitCommon *GitCommon) *CustomCommands { return &CustomCommands{ - Common: common, - cmd: cmd, + GitCommon: gitCommon, } } diff --git a/pkg/commands/git_commands/deps_test.go b/pkg/commands/git_commands/deps_test.go index 186ce1d87..834d51b55 100644 --- a/pkg/commands/git_commands/deps_test.go +++ b/pkg/commands/git_commands/deps_test.go @@ -22,120 +22,123 @@ type commonDeps struct { cmd *oscommands.CmdObjBuilder } -func completeDeps(deps commonDeps) commonDeps { - if deps.runner == nil { - deps.runner = oscommands.NewFakeRunner(nil) - } +func buildGitCommon(deps commonDeps) *GitCommon { + gitCommon := &GitCommon{} - if deps.userConfig == nil { - deps.userConfig = config.GetDefaultConfig() + gitCommon.Common = deps.common + if gitCommon.Common == nil { + gitCommon.Common = utils.NewDummyCommonWithUserConfig(deps.userConfig) } - if deps.gitConfig == nil { - deps.gitConfig = git_config.NewFakeGitConfig(nil) + runner := deps.runner + if runner == nil { + runner = oscommands.NewFakeRunner(nil) } - if deps.getenv == nil { - deps.getenv = func(string) string { return "" } + cmd := deps.cmd + // gotta check deps.cmd because it's not an interface type and an interface value of nil is not considered to be nil + if cmd == nil { + cmd = oscommands.NewDummyCmdObjBuilder(runner) } + gitCommon.cmd = cmd - if deps.removeFile == nil { - deps.removeFile = func(string) error { return errors.New("unexpected call to removeFile") } + gitCommon.Common.UserConfig = deps.userConfig + if gitCommon.Common.UserConfig == nil { + gitCommon.Common.UserConfig = config.GetDefaultConfig() } - if deps.dotGitDir == "" { - deps.dotGitDir = ".git" + gitConfig := deps.gitConfig + if gitConfig == nil { + gitConfig = git_config.NewFakeGitConfig(nil) } - if deps.common == nil { - deps.common = utils.NewDummyCommonWithUserConfig(deps.userConfig) - } + gitCommon.repo = buildRepo() + gitCommon.config = NewConfigCommands(gitCommon.Common, gitConfig, gitCommon.repo) - if deps.cmd == nil { - deps.cmd = oscommands.NewDummyCmdObjBuilder(deps.runner) + getenv := deps.getenv + if getenv == nil { + getenv = func(string) string { return "" } } - return deps -} + removeFile := deps.removeFile + if removeFile == nil { + removeFile = func(string) error { return errors.New("unexpected call to removeFile") } + } -func buildConfigCommands(deps commonDeps) *ConfigCommands { - deps = completeDeps(deps) - common := utils.NewDummyCommonWithUserConfig(deps.userConfig) + gitCommon.os = oscommands.NewDummyOSCommandWithDeps(oscommands.OSCommandDeps{ + Common: gitCommon.Common, + GetenvFn: getenv, + Cmd: cmd, + RemoveFileFn: removeFile, + }) - // TODO: think of a way to actually mock this outnil - var repo *gogit.Repository = nil + gitCommon.dotGitDir = deps.dotGitDir + if gitCommon.dotGitDir == "" { + gitCommon.dotGitDir = ".git" + } - return NewConfigCommands(common, deps.gitConfig, repo) + return gitCommon } -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 buildRepo() *gogit.Repository { + // TODO: think of a way to actually mock this out + var repo *gogit.Repository = nil + return repo } -func buildFileLoader(deps commonDeps) *loaders.FileLoader { - deps = completeDeps(deps) - - configCommands := buildConfigCommands(deps) - - return loaders.NewFileLoader(deps.common, deps.cmd, configCommands) +func buildFileLoader(gitCommon *GitCommon) *loaders.FileLoader { + return loaders.NewFileLoader(gitCommon.Common, gitCommon.cmd, gitCommon.config) } func buildSubmoduleCommands(deps commonDeps) *SubmoduleCommands { - deps = completeDeps(deps) + gitCommon := buildGitCommon(deps) - return NewSubmoduleCommands(deps.common, deps.cmd, deps.dotGitDir) + return NewSubmoduleCommands(gitCommon) } func buildCommitCommands(deps commonDeps) *CommitCommands { - deps = completeDeps(deps) - return NewCommitCommands(deps.common, deps.cmd) + gitCommon := buildGitCommon(deps) + return NewCommitCommands(gitCommon) } func buildWorkingTreeCommands(deps commonDeps) *WorkingTreeCommands { - deps = completeDeps(deps) - osCommand := buildOSCommand(deps) + gitCommon := buildGitCommon(deps) submoduleCommands := buildSubmoduleCommands(deps) - fileLoader := buildFileLoader(deps) + fileLoader := buildFileLoader(gitCommon) - return NewWorkingTreeCommands(deps.common, deps.cmd, submoduleCommands, osCommand, fileLoader) + return NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader) } func buildStashCommands(deps commonDeps) *StashCommands { - deps = completeDeps(deps) - osCommand := buildOSCommand(deps) - fileLoader := buildFileLoader(deps) + gitCommon := buildGitCommon(deps) + fileLoader := buildFileLoader(gitCommon) workingTreeCommands := buildWorkingTreeCommands(deps) - return NewStashCommands(deps.common, deps.cmd, osCommand, fileLoader, workingTreeCommands) + return NewStashCommands(gitCommon, fileLoader, workingTreeCommands) } func buildRebaseCommands(deps commonDeps) *RebaseCommands { - deps = completeDeps(deps) - configCommands := buildConfigCommands(deps) - osCommand := buildOSCommand(deps) + gitCommon := buildGitCommon(deps) workingTreeCommands := buildWorkingTreeCommands(deps) commitCommands := buildCommitCommands(deps) - return NewRebaseCommands(deps.common, deps.cmd, osCommand, commitCommands, workingTreeCommands, configCommands, deps.dotGitDir) + return NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands) } func buildSyncCommands(deps commonDeps) *SyncCommands { - deps = completeDeps(deps) + gitCommon := buildGitCommon(deps) - return NewSyncCommands(deps.common, deps.cmd) + return NewSyncCommands(gitCommon) } func buildFileCommands(deps commonDeps) *FileCommands { - deps = completeDeps(deps) - configCommands := buildConfigCommands(deps) - osCommand := buildOSCommand(deps) + gitCommon := buildGitCommon(deps) + + return NewFileCommands(gitCommon) +} + +func buildBranchCommands(deps commonDeps) *BranchCommands { + gitCommon := buildGitCommon(deps) - return NewFileCommands(deps.common, deps.cmd, configCommands, osCommand) + return NewBranchCommands(gitCommon) } diff --git a/pkg/commands/git_commands/file.go b/pkg/commands/git_commands/file.go index 070a50790..026d79cb0 100644 --- a/pkg/commands/git_commands/file.go +++ b/pkg/commands/git_commands/file.go @@ -5,34 +5,16 @@ import ( "strconv" "github.com/go-errors/errors" - "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/utils" ) type FileCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder - config *ConfigCommands - os FileOSCommand -} - -type FileOSCommand interface { - Getenv(string) string + *GitCommon } -func NewFileCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, - config *ConfigCommands, - osCommand FileOSCommand, -) *FileCommands { +func NewFileCommands(gitCommon *GitCommon) *FileCommands { return &FileCommands{ - Common: common, - cmd: cmd, - config: config, - os: osCommand, + GitCommon: gitCommon, } } diff --git a/pkg/commands/git_commands/flow.go b/pkg/commands/git_commands/flow.go index 6a061b537..fd97707ec 100644 --- a/pkg/commands/git_commands/flow.go +++ b/pkg/commands/git_commands/flow.go @@ -6,25 +6,17 @@ import ( "github.com/go-errors/errors" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" ) type FlowCommands struct { - *common.Common - - config *ConfigCommands - cmd oscommands.ICmdObjBuilder + *GitCommon } func NewFlowCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, - config *ConfigCommands, + gitCommon *GitCommon, ) *FlowCommands { return &FlowCommands{ - Common: common, - cmd: cmd, - config: config, + GitCommon: gitCommon, } } diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index 64661cd71..8f9ce5784 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -5,40 +5,34 @@ 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/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" - "github.com/jesseduffield/lazygit/pkg/common" ) type PatchCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder - rebase *RebaseCommands - commit *CommitCommands - config *ConfigCommands - stash *StashCommands - status *StatusCommands + *GitCommon + rebase *RebaseCommands + commit *CommitCommands + status *StatusCommands + stash *StashCommands + PatchManager *patch.PatchManager } func NewPatchCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, - rebaseCommands *RebaseCommands, - commitCommands *CommitCommands, - configCommands *ConfigCommands, - statusCommands *StatusCommands, + gitCommon *GitCommon, + rebase *RebaseCommands, + commit *CommitCommands, + status *StatusCommands, + stash *StashCommands, patchManager *patch.PatchManager, ) *PatchCommands { return &PatchCommands{ - Common: common, - cmd: cmd, - rebase: rebaseCommands, - commit: commitCommands, - config: configCommands, - status: statusCommands, + GitCommon: gitCommon, + rebase: rebase, + commit: commit, + status: status, + stash: stash, PatchManager: patchManager, } } diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index b939b34f5..c726cad7e 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -9,39 +9,25 @@ 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/common" ) type RebaseCommands struct { - *common.Common + *GitCommon + commit *CommitCommands + workingTree *WorkingTreeCommands - cmd oscommands.ICmdObjBuilder - osCommand *oscommands.OSCommand - - commit *CommitCommands - workingTree *WorkingTreeCommands - config *ConfigCommands - dotGitDir string onSuccessfulContinue func() error } func NewRebaseCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, - osCommand *oscommands.OSCommand, + gitCommon *GitCommon, commitCommands *CommitCommands, workingTreeCommands *WorkingTreeCommands, - configCommands *ConfigCommands, - dotGitDir string, ) *RebaseCommands { return &RebaseCommands{ - Common: common, - cmd: cmd, - osCommand: osCommand, + GitCommon: gitCommon, commit: commitCommands, workingTree: workingTreeCommands, - config: configCommands, - dotGitDir: dotGitDir, } } @@ -119,7 +105,7 @@ func (self *RebaseCommands) PrepareInteractiveRebaseCommand(baseSha string, todo if todo == "" { gitSequenceEditor = "true" } else { - self.osCommand.LogCommand(fmt.Sprintf("Creating TODO file for interactive rebase: \n\n%s", todo), false) + self.os.LogCommand(fmt.Sprintf("Creating TODO file for interactive rebase: \n\n%s", todo), false) } cmdObj.AddEnvVars( @@ -328,7 +314,7 @@ func (self *RebaseCommands) DiscardOldFileChanges(commits []*models.Commit, comm // check if file exists in previous commit (this command returns an error if the file doesn't exist) if err := self.cmd.New("git cat-file -e HEAD^:" + self.cmd.Quote(fileName)).Run(); err != nil { - if err := self.osCommand.Remove(fileName); err != nil { + if err := self.os.Remove(fileName); err != nil { return err } if err := self.workingTree.StageFile(fileName); err != nil { diff --git a/pkg/commands/git_commands/remote.go b/pkg/commands/git_commands/remote.go index fe8ab57b0..3116c764a 100644 --- a/pkg/commands/git_commands/remote.go +++ b/pkg/commands/git_commands/remote.go @@ -2,24 +2,15 @@ package git_commands import ( "fmt" - - "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" ) type RemoteCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder + *GitCommon } -func NewRemoteCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, -) *RemoteCommands { +func NewRemoteCommands(gitCommon *GitCommon) *RemoteCommands { return &RemoteCommands{ - Common: common, - cmd: cmd, + GitCommon: gitCommon, } } diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 9141c1702..d20024aa9 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -5,30 +5,22 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/common" ) type StashCommands struct { - *common.Common - - cmd oscommands.ICmdObjBuilder + *GitCommon fileLoader *loaders.FileLoader - osCommand *oscommands.OSCommand workingTree *WorkingTreeCommands } func NewStashCommands( - common *common.Common, - cmd oscommands.ICmdObjBuilder, - osCommand *oscommands.OSCommand, + gitCommon *GitCommon, fileLoader *loaders.FileLoader, workingTree *WorkingTreeCommands, ) *StashCommands { return &StashCommands{ - Common: common, - cmd: cmd, + GitCommon: gitCommon, fileLoader: fileLoader, - osCommand: osCommand, workingTree: workingTree, } } @@ -73,7 +65,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error { return err } - if err := self.osCommand.PipeCommands("git stash show -p", "git apply -R"); err != nil { + if err := self.os.PipeCommands("git stash show -p", "git apply -R"); err != nil { return err } diff --git a/pkg/commands/git_commands/status.go b/pkg/commands/git_commands/status.go index fe89646d2..50b1fab57 100644 --- a/pkg/commands/git_commands/status.go +++ b/pkg/commands/git_commands/status.go @@ -4,43 +4,32 @@ import ( "path/filepath" gogit "github.com/jesseduffield/go-git/v5" - "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" - "github.com/jesseduffield/lazygit/pkg/common" ) type StatusCommands struct { - *common.Common - osCommand *oscommands.OSCommand - repo *gogit.Repository - dotGitDir string + *GitCommon } func NewStatusCommands( - common *common.Common, - osCommand *oscommands.OSCommand, - repo *gogit.Repository, - dotGitDir string, + gitCommon *GitCommon, ) *StatusCommands { return &StatusCommands{ - Common: common, - osCommand: osCommand, - repo: repo, - dotGitDir: dotGitDir, + GitCommon: gitCommon, } } // RebaseMode returns "" for non-rebase mode, "normal" for normal rebase // and "interactive" for interactive rebase func (self *StatusCommands) RebaseMode() (enums.RebaseMode, error) { - exists, err := self.osCommand.FileExists(filepath.Join(self.dotGitDir, "rebase-app |