Skip to content

Commit a400ef0

Browse files
committed
Remove ICmdObj interface
It is only implemented by *CmdObj, so use that directly in client code.
1 parent 4e3d09e commit a400ef0

25 files changed

+137
-178
lines changed

pkg/commands/git_cmd_obj_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func NewGitCmdObjBuilder(log *logrus.Entry, innerBuilder *oscommands.CmdObjBuild
3030

3131
var defaultEnvVar = "GIT_OPTIONAL_LOCKS=0"
3232

33-
func (self *gitCmdObjBuilder) New(args []string) oscommands.ICmdObj {
33+
func (self *gitCmdObjBuilder) New(args []string) *oscommands.CmdObj {
3434
return self.innerBuilder.New(args).AddEnvVars(defaultEnvVar)
3535
}
3636

37-
func (self *gitCmdObjBuilder) NewShell(cmdStr string, shellFunctionsFile string) oscommands.ICmdObj {
37+
func (self *gitCmdObjBuilder) NewShell(cmdStr string, shellFunctionsFile string) *oscommands.CmdObj {
3838
return self.innerBuilder.NewShell(cmdStr, shellFunctionsFile).AddEnvVars(defaultEnvVar)
3939
}
4040

pkg/commands/git_cmd_obj_runner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ type gitCmdObjRunner struct {
2020
innerRunner oscommands.ICmdObjRunner
2121
}
2222

23-
func (self *gitCmdObjRunner) Run(cmdObj oscommands.ICmdObj) error {
23+
func (self *gitCmdObjRunner) Run(cmdObj *oscommands.CmdObj) error {
2424
_, err := self.RunWithOutput(cmdObj)
2525
return err
2626
}
2727

28-
func (self *gitCmdObjRunner) RunWithOutput(cmdObj oscommands.ICmdObj) (string, error) {
28+
func (self *gitCmdObjRunner) RunWithOutput(cmdObj *oscommands.CmdObj) (string, error) {
2929
var output string
3030
var err error
3131
for i := 0; i < RetryCount; i++ {
@@ -44,7 +44,7 @@ func (self *gitCmdObjRunner) RunWithOutput(cmdObj oscommands.ICmdObj) (string, e
4444
return output, err
4545
}
4646

47-
func (self *gitCmdObjRunner) RunWithOutputs(cmdObj oscommands.ICmdObj) (string, string, error) {
47+
func (self *gitCmdObjRunner) RunWithOutputs(cmdObj *oscommands.CmdObj) (string, string, error) {
4848
var stdout, stderr string
4949
var err error
5050
for i := 0; i < RetryCount; i++ {
@@ -64,6 +64,6 @@ func (self *gitCmdObjRunner) RunWithOutputs(cmdObj oscommands.ICmdObj) (string,
6464
}
6565

6666
// Retry logic not implemented here, but these commands typically don't need to obtain a lock.
67-
func (self *gitCmdObjRunner) RunAndProcessLines(cmdObj oscommands.ICmdObj, onLine func(line string) (bool, error)) error {
67+
func (self *gitCmdObjRunner) RunAndProcessLines(cmdObj *oscommands.CmdObj, onLine func(line string) (bool, error)) error {
6868
return self.innerRunner.RunAndProcessLines(cmdObj, onLine)
6969
}

pkg/commands/git_commands/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (self *BranchCommands) GetGraph(branchName string) (string, error) {
154154
return self.GetGraphCmdObj(branchName).DontLog().RunWithOutput()
155155
}
156156

157-
func (self *BranchCommands) GetGraphCmdObj(branchName string) oscommands.ICmdObj {
157+
func (self *BranchCommands) GetGraphCmdObj(branchName string) *oscommands.CmdObj {
158158
branchLogCmdTemplate := self.UserConfig().Git.BranchLogCmd
159159
templateValues := map[string]string{
160160
"branchName": self.cmd.Quote(branchName),
@@ -255,7 +255,7 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error {
255255
return self.cmd.New(cmdArgs).Run()
256256
}
257257

258-
func (self *BranchCommands) AllBranchesLogCmdObj() oscommands.ICmdObj {
258+
func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
259259
// Only choose between non-empty, non-identical commands
260260
candidates := lo.Uniq(lo.WithoutEmpty(append([]string{
261261
self.UserConfig().Git.AllBranchesLogCmd,

pkg/commands/git_commands/commit.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (self *CommitCommands) ResetToCommit(hash string, strength string, envVars
8585
Run()
8686
}
8787

88-
func (self *CommitCommands) CommitCmdObj(summary string, description string, forceSkipHooks bool) oscommands.ICmdObj {
88+
func (self *CommitCommands) CommitCmdObj(summary string, description string, forceSkipHooks bool) *oscommands.CmdObj {
8989
messageArgs := self.commitMessageArgs(summary, description)
9090
skipHookPrefix := self.UserConfig().Git.SkipHookPrefix
9191
cmdArgs := NewGitCmd("commit").
@@ -97,16 +97,16 @@ func (self *CommitCommands) CommitCmdObj(summary string, description string, for
9797
return self.cmd.New(cmdArgs)
9898
}
9999

100-
func (self *CommitCommands) RewordLastCommitInEditorCmdObj() oscommands.ICmdObj {
100+
func (self *CommitCommands) RewordLastCommitInEditorCmdObj() *oscommands.CmdObj {
101101
return self.cmd.New(NewGitCmd("commit").Arg("--allow-empty", "--amend", "--only").ToArgv())
102102
}
103103

104-
func (self *CommitCommands) RewordLastCommitInEditorWithMessageFileCmdObj(tmpMessageFile string) oscommands.ICmdObj {
104+
func (self *CommitCommands) RewordLastCommitInEditorWithMessageFileCmdObj(tmpMessageFile string) *oscommands.CmdObj {
105105
return self.cmd.New(NewGitCmd("commit").
106106
Arg("--allow-empty", "--amend", "--only", "--edit", "--file="+tmpMessageFile).ToArgv())
107107
}
108108

109-
func (self *CommitCommands) CommitInEditorWithMessageFileCmdObj(tmpMessageFile string, forceSkipHooks bool) oscommands.ICmdObj {
109+
func (self *CommitCommands) CommitInEditorWithMessageFileCmdObj(tmpMessageFile string, forceSkipHooks bool) *oscommands.CmdObj {
110110
return self.cmd.New(NewGitCmd("commit").
111111
ArgIf(forceSkipHooks, "--no-verify").
112112
Arg("--edit").
@@ -116,7 +116,7 @@ func (self *CommitCommands) CommitInEditorWithMessageFileCmdObj(tmpMessageFile s
116116
}
117117

118118
// RewordLastCommit rewords the topmost commit with the given message
119-
func (self *CommitCommands) RewordLastCommit(summary string, description string) oscommands.ICmdObj {
119+
func (self *CommitCommands) RewordLastCommit(summary string, description string) *oscommands.CmdObj {
120120
messageArgs := self.commitMessageArgs(summary, description)
121121

122122
cmdArgs := NewGitCmd("commit").
@@ -138,7 +138,7 @@ func (self *CommitCommands) commitMessageArgs(summary string, description string
138138
}
139139

140140
// runs git commit without the -m argument meaning it will invoke the user's editor
141-
func (self *CommitCommands) CommitEditorCmdObj() oscommands.ICmdObj {
141+
func (self *CommitCommands) CommitEditorCmdObj() *oscommands.CmdObj {
142142
cmdArgs := NewGitCmd("commit").
143143
ArgIf(self.signoffFlag() != "", self.signoffFlag()).
144144
ToArgv()
@@ -246,15 +246,15 @@ func (self *CommitCommands) AmendHead() error {
246246
return self.AmendHeadCmdObj().Run()
247247
}
248248

249-
func (self *CommitCommands) AmendHeadCmdObj() oscommands.ICmdObj {
249+
func (self *CommitCommands) AmendHeadCmdObj() *oscommands.CmdObj {
250250
cmdArgs := NewGitCmd("commit").
251251
Arg("--amend", "--no-edit", "--allow-empty").
252252
ToArgv()
253253

254254
return self.cmd.New(cmdArgs)
255255
}
256256

257-
func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) oscommands.ICmdObj {
257+
func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) *oscommands.CmdObj {
258258
contextSize := self.AppState.DiffContextSize
259259

260260
extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand
@@ -278,7 +278,7 @@ func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) oscommand
278278
return self.cmd.New(cmdArgs).DontLog()
279279
}
280280

281-
func (self *CommitCommands) ShowFileContentCmdObj(hash string, filePath string) oscommands.ICmdObj {
281+
func (self *CommitCommands) ShowFileContentCmdObj(hash string, filePath string) *oscommands.CmdObj {
282282
cmdArgs := NewGitCmd("show").
283283
Arg(fmt.Sprintf("%s:%s", hash, filePath)).
284284
ToArgv()

pkg/commands/git_commands/commit_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func (self *CommitLoader) getFirstPushedCommit(refName string) (string, error) {
583583
}
584584

585585
// getLog gets the git log.
586-
func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
586+
func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj {
587587
gitLogOrder := self.AppState.GitLogOrder
588588

589589
refSpec := opts.RefName

pkg/commands/git_commands/diff.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func NewDiffCommands(gitCommon *GitCommon) *DiffCommands {
1818

1919
// This is for generating diffs to be shown in the UI (e.g. rendering a range
2020
// diff to the main view). It uses a custom pager if one is configured.
21-
func (self *DiffCommands) DiffCmdObj(diffArgs []string) oscommands.ICmdObj {
21+
func (self *DiffCommands) DiffCmdObj(diffArgs []string) *oscommands.CmdObj {
2222
extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand
2323
useExtDiff := extDiffCmd != ""
2424
ignoreWhitespace := self.AppState.IgnoreWhitespaceInDiffView
@@ -83,7 +83,7 @@ type DiffToolCmdOptions struct {
8383
Staged bool
8484
}
8585

86-
func (self *DiffCommands) OpenDiffToolCmdObj(opts DiffToolCmdOptions) oscommands.ICmdObj {
86+
func (self *DiffCommands) OpenDiffToolCmdObj(opts DiffToolCmdOptions) *oscommands.CmdObj {
8787
return self.cmd.New(NewGitCmd("difftool").
8888
Arg("--no-prompt").
8989
ArgIf(opts.IsDirectory, "--dir-diff").
@@ -95,7 +95,7 @@ func (self *DiffCommands) OpenDiffToolCmdObj(opts DiffToolCmdOptions) oscommands
9595
ToArgv())
9696
}
9797

98-
func (self *DiffCommands) DiffIndexCmdObj(diffArgs ...string) oscommands.ICmdObj {
98+
func (self *DiffCommands) DiffIndexCmdObj(diffArgs ...string) *oscommands.CmdObj {
9999
return self.cmd.New(
100100
NewGitCmd("diff-index").
101101
Config("diff.noprefix=false").

pkg/commands/git_commands/flow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (self *FlowCommands) GitFlowEnabled() bool {
2424
return self.config.GetGitFlowPrefixes() != ""
2525
}
2626

27-
func (self *FlowCommands) FinishCmdObj(branchName string) (oscommands.ICmdObj, error) {
27+
func (self *FlowCommands) FinishCmdObj(branchName string) (*oscommands.CmdObj, error) {
2828
prefixes := self.config.GetGitFlowPrefixes()
2929

3030
// need to find out what kind of branch this is
@@ -54,7 +54,7 @@ func (self *FlowCommands) FinishCmdObj(branchName string) (oscommands.ICmdObj, e
5454
return self.cmd.New(cmdArgs), nil
5555
}
5656

57-
func (self *FlowCommands) StartCmdObj(branchType string, name string) oscommands.ICmdObj {
57+
func (self *FlowCommands) StartCmdObj(branchType string, name string) *oscommands.CmdObj {
5858
cmdArgs := NewGitCmd("flow").Arg(branchType, "start", name).ToArgv()
5959

6060
return self.cmd.New(cmdArgs)

pkg/commands/git_commands/rebase.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, su
5353
return self.ContinueRebase()
5454
}
5555

56-
func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index int) (oscommands.ICmdObj, error) {
56+
func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index int) (*oscommands.CmdObj, error) {
5757
changes := []daemon.ChangeTodoAction{{
5858
Hash: commits[index].Hash(),
5959
NewAction: todo.Reword,
@@ -209,7 +209,7 @@ type PrepareInteractiveRebaseCommandOpts struct {
209209
// PrepareInteractiveRebaseCommand returns the cmd for an interactive rebase
210210
// we tell git to run lazygit to edit the todo list, and we pass the client
211211
// lazygit instructions what to do with the todo file
212-
func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteractiveRebaseCommandOpts) oscommands.ICmdObj {
212+
func (self *RebaseCommands) PrepareInteractiveRebaseCommand(opts PrepareInteractiveRebaseCommandOpts) *oscommands.CmdObj {
213213
ex := oscommands.GetLazygitPath()
214214

215215
cmdArgs := NewGitCmd("rebase").
@@ -446,7 +446,7 @@ func (self *RebaseCommands) RebaseBranchFromBaseCommit(targetBranchName string,
446446
}).Run()
447447
}
448448

449-
func (self *RebaseCommands) GenericMergeOrRebaseActionCmdObj(commandType string, command string) oscommands.ICmdObj {
449+
func (self *RebaseCommands) GenericMergeOrRebaseActionCmdObj(commandType string, command string) *oscommands.CmdObj {
450450
cmdArgs := NewGitCmd(commandType).Arg("--" + command).ToArgv()
451451

452452
return self.cmd.New(cmdArgs)
@@ -485,7 +485,7 @@ func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, comma
485485
return nil
486486
}
487487

488-
func (self *RebaseCommands) runSkipEditorCommand(cmdObj oscommands.ICmdObj) error {
488+
func (self *RebaseCommands) runSkipEditorCommand(cmdObj *oscommands.CmdObj) error {
489489
instruction := daemon.NewExitImmediatelyInstruction()
490490
lazyGitPath := oscommands.GetLazygitPath()
491491
return cmdObj.

pkg/commands/git_commands/rebase_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestRebaseRebaseBranch(t *testing.T) {
6969
// environment variables that suppress an interactive editor
7070
func TestRebaseSkipEditorCommand(t *testing.T) {
7171
cmdArgs := []string{"git", "blah"}
72-
runner := oscommands.NewFakeRunner(t).ExpectFunc("matches editor env var", func(cmdObj oscommands.ICmdObj) bool {
72+
runner := oscommands.NewFakeRunner(t).ExpectFunc("matches editor env var", func(cmdObj *oscommands.CmdObj) bool {
7373
assert.EqualValues(t, cmdArgs, cmdObj.Args())
7474
envVars := cmdObj.GetEnvVars()
7575
for _, regexStr := range []string{

pkg/commands/git_commands/stash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (self *StashCommands) Hash(index int) (string, error) {
8080
return strings.Trim(hash, "\r\n"), err
8181
}
8282

83-
func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
83+
func (self *StashCommands) ShowStashEntryCmdObj(index int) *oscommands.CmdObj {
8484
// "-u" is the same as "--include-untracked", but the latter fails in older git versions for some reason
8585
cmdArgs := NewGitCmd("stash").Arg("show").
8686
Arg("-p").

0 commit comments

Comments
 (0)