summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-07 20:33:34 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-09 14:09:53 +1100
commitee8ff6512f50803a70a8ad8919dbfa6aa6ea089b (patch)
tree37f1fa95893eaac47c8109fadb997dc9994a8abe /pkg
parente8229f0ee0eafb2d94674a091cb7a8776468e9c1 (diff)
trim down gitcommand struct some more
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/custom.go29
-rw-r--r--pkg/commands/git.go7
-rw-r--r--pkg/commands/rebasing.go23
-rw-r--r--pkg/gui/custom_commands.go2
-rw-r--r--pkg/gui/git_flow.go20
-rw-r--r--pkg/gui/rebase_options_panel.go9
6 files changed, 58 insertions, 32 deletions
diff --git a/pkg/commands/custom.go b/pkg/commands/custom.go
new file mode 100644
index 000000000..a9bf64bf4
--- /dev/null
+++ b/pkg/commands/custom.go
@@ -0,0 +1,29 @@
+package commands
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/common"
+)
+
+type CustomCommands struct {
+ *common.Common
+
+ cmd oscommands.ICmdObjBuilder
+}
+
+func NewCustomCommands(
+ common *common.Common,
+ cmd oscommands.ICmdObjBuilder,
+) *CustomCommands {
+ return &CustomCommands{
+ Common: common,
+ cmd: cmd,
+ }
+}
+
+// Only to be used for the sake of running custom commands specified by the user.
+// If you want to run a new command, try finding a place for it in one of the neighbouring
+// files, or creating a new BlahCommands struct to hold it.
+func (self *CustomCommands) RunWithOutput(cmdStr string) (string, error) {
+ return self.cmd.New(cmdStr).RunWithOutput()
+}
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 4ca2631cf..59d5b90ef 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -22,8 +22,6 @@ import (
type GitCommand struct {
Loaders Loaders
- Cmd oscommands.ICmdObjBuilder
-
Submodule *SubmoduleCommands
Tag *TagCommands
WorkingTree *WorkingTreeCommands
@@ -38,6 +36,7 @@ type GitCommand struct {
Remote *RemoteCommands
Sync *SyncCommands
Flow *FlowCommands
+ Custom *CustomCommands
}
type Loaders struct {
@@ -101,6 +100,7 @@ func NewGitCommandAux(
syncCommands := NewSyncCommands(cmn, cmd)
tagCommands := NewTagCommands(cmn, cmd)
commitCommands := NewCommitCommands(cmn, cmd)
+ customCommands := NewCustomCommands(cmn, cmd)
fileCommands := NewFileCommands(cmn, cmd, configCommands, osCommand)
submoduleCommands := NewSubmoduleCommands(cmn, cmd, dotGitDir)
workingTreeCommands := NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
@@ -119,8 +119,6 @@ func NewGitCommandAux(
patchCommands := NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager)
return &GitCommand{
- Cmd: cmd,
-
Submodule: submoduleCommands,
Tag: tagCommands,
WorkingTree: workingTreeCommands,
@@ -135,6 +133,7 @@ func NewGitCommandAux(
Remote: remoteCommands,
Sync: syncCommands,
Flow: flowCommands,
+ Custom: customCommands,
Loaders: Loaders{
Commits: loaders.NewCommitLoader(cmn, cmd, dotGitDir, branchCommands.CurrentBranchName, statusCommands.RebaseMode),
Branches: loaders.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchName),
diff --git a/pkg/commands/rebasing.go b/pkg/commands/rebasing.go
index e845c5ed3..4bc92238d 100644
--- a/pkg/commands/rebasing.go
+++ b/pkg/commands/rebasing.go
@@ -225,9 +225,11 @@ func (self *RebaseCommands) MoveTodoDown(index int) error {
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error {
return self.runSkipEditorCommand(
- fmt.Sprintf(
- "git rebase --interactive --autostash --autosquash %s^",
- sha,
+ self.cmd.New(
+ fmt.Sprintf(
+ "git rebase --interactive --autostash --autosquash %s^",
+ sha,
+ ),
),
)
}
@@ -269,16 +271,14 @@ func (self *RebaseCommands) RebaseBranch(branchName string) error {
return cmdObj.Run()
}
+func (self *RebaseCommands) GenericMergeOrRebaseActionCmdObj(commandType string, command string) oscommands.ICmdObj {
+ return self.cmd.New("git " + commandType + " --" + command)
+}
+
// GenericMerge takes a commandType of "merge" or "rebase" and a command of "abort", "skip" or "continue"
// By default we skip the editor in the case where a commit will be made
func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, command string) error {
- err := self.runSkipEditorCommand(
- fmt.Sprintf(
- "git %s --%s",
- commandType,
- command,
- ),
- )
+ err := self.runSkipEditorCommand(self.GenericMergeOrRebaseActionCmdObj(commandType, command))
if err != nil {
if !strings.Contains(err.Error(), "no rebase in progress") {
return err
@@ -300,8 +300,7 @@ func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, comma
return nil
}
-func (self *RebaseCommands) runSkipEditorCommand(command string) error {
- cmdObj := self.cmd.New(command)
+func (self *RebaseCommands) runSkipEditorCommand(cmdObj oscommands.ICmdObj) error {
lazyGitPath := oscommands.GetLazygitPath()
return cmdObj.
AddEnvVars(
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go
index cc64be4a2..e7a7cbad1 100644
--- a/pkg/gui/custom_commands.go
+++ b/pkg/gui/custom_commands.go
@@ -203,7 +203,7 @@ func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptR
}
// Run and save output
- message, err := gui.GitCommand.Cmd.New(cmdStr).RunWithOutput()
+ message, err := gui.GitCommand.Custom.RunWithOutput(cmdStr)
if err != nil {
return gui.surfaceError(err)
}
diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go
index 959f22788..842f6c0cd 100644
--- a/pkg/gui/git_flow.go
+++ b/pkg/gui/git_flow.go
@@ -6,16 +6,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
-func (gui *Gui) gitFlowFinishBranch(branchName string) error {
- cmdObj, err := gui.GitCommand.Flow.FinishCmdObj(branchName)
- if err != nil {
- return gui.surfaceError(err)
- }
-
- gui.logAction(gui.Tr.Actions.GitFlowFinish)
- return gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
-}
-
func (gui *Gui) handleCreateGitFlowMenu() error {
branch := gui.getSelectedBranch()
if branch == nil {
@@ -70,3 +60,13 @@ func (gui *Gui) handleCreateGitFlowMenu() error {
return gui.createMenu("git flow", menuItems, createMenuOptions{})
}
+
+func (gui *Gui) gitFlowFinishBranch(branchName string) error {
+ cmdObj, err := gui.GitCommand.Flow.FinishCmdObj(branchName)
+ if err != nil {
+ return gui.surfaceError(err)
+ }
+
+ gui.logAction(gui.Tr.Actions.GitFlowFinish)
+ return gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
+}
diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go
index e9476cd5d..482640fa2 100644
--- a/pkg/gui/rebase_options_panel.go
+++ b/pkg/gui/rebase_options_panel.go
@@ -65,11 +65,10 @@ func (gui *Gui) genericMergeCommand(command string) error {
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
if status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.UserConfig.Git.Merging.ManualCommit {
- sub := gui.GitCommand.Cmd.New("git " + commandType + " --" + command)
- if sub != nil {
- return gui.runSubprocessWithSuspenseAndRefresh(sub)
- }
- return nil
+ // TODO: see if we should be calling more of the code from gui.GitCommand.Rebase.GenericMergeOrRebaseAction
+ return gui.runSubprocessWithSuspenseAndRefresh(
+ gui.GitCommand.Rebase.GenericMergeOrRebaseActionCmdObj(commandType, command),
+ )
}
result := gui.GitCommand.Rebase.GenericMergeOrRebaseAction(commandType, command)
if err := gui.handleGenericMergeCommandResult(result); err != nil {