mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
trim down gitcommand struct some more
This commit is contained in:
parent
e8229f0ee0
commit
ee8ff6512f
29
pkg/commands/custom.go
Normal file
29
pkg/commands/custom.go
Normal file
@ -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()
|
||||||
|
}
|
@ -22,8 +22,6 @@ import (
|
|||||||
type GitCommand struct {
|
type GitCommand struct {
|
||||||
Loaders Loaders
|
Loaders Loaders
|
||||||
|
|
||||||
Cmd oscommands.ICmdObjBuilder
|
|
||||||
|
|
||||||
Submodule *SubmoduleCommands
|
Submodule *SubmoduleCommands
|
||||||
Tag *TagCommands
|
Tag *TagCommands
|
||||||
WorkingTree *WorkingTreeCommands
|
WorkingTree *WorkingTreeCommands
|
||||||
@ -38,6 +36,7 @@ type GitCommand struct {
|
|||||||
Remote *RemoteCommands
|
Remote *RemoteCommands
|
||||||
Sync *SyncCommands
|
Sync *SyncCommands
|
||||||
Flow *FlowCommands
|
Flow *FlowCommands
|
||||||
|
Custom *CustomCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
type Loaders struct {
|
type Loaders struct {
|
||||||
@ -101,6 +100,7 @@ func NewGitCommandAux(
|
|||||||
syncCommands := NewSyncCommands(cmn, cmd)
|
syncCommands := NewSyncCommands(cmn, cmd)
|
||||||
tagCommands := NewTagCommands(cmn, cmd)
|
tagCommands := NewTagCommands(cmn, cmd)
|
||||||
commitCommands := NewCommitCommands(cmn, cmd)
|
commitCommands := NewCommitCommands(cmn, cmd)
|
||||||
|
customCommands := NewCustomCommands(cmn, cmd)
|
||||||
fileCommands := NewFileCommands(cmn, cmd, configCommands, osCommand)
|
fileCommands := NewFileCommands(cmn, cmd, configCommands, osCommand)
|
||||||
submoduleCommands := NewSubmoduleCommands(cmn, cmd, dotGitDir)
|
submoduleCommands := NewSubmoduleCommands(cmn, cmd, dotGitDir)
|
||||||
workingTreeCommands := NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
|
workingTreeCommands := NewWorkingTreeCommands(cmn, cmd, submoduleCommands, osCommand, fileLoader)
|
||||||
@ -119,8 +119,6 @@ func NewGitCommandAux(
|
|||||||
patchCommands := NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager)
|
patchCommands := NewPatchCommands(cmn, cmd, rebaseCommands, commitCommands, configCommands, statusCommands, patchManager)
|
||||||
|
|
||||||
return &GitCommand{
|
return &GitCommand{
|
||||||
Cmd: cmd,
|
|
||||||
|
|
||||||
Submodule: submoduleCommands,
|
Submodule: submoduleCommands,
|
||||||
Tag: tagCommands,
|
Tag: tagCommands,
|
||||||
WorkingTree: workingTreeCommands,
|
WorkingTree: workingTreeCommands,
|
||||||
@ -135,6 +133,7 @@ func NewGitCommandAux(
|
|||||||
Remote: remoteCommands,
|
Remote: remoteCommands,
|
||||||
Sync: syncCommands,
|
Sync: syncCommands,
|
||||||
Flow: flowCommands,
|
Flow: flowCommands,
|
||||||
|
Custom: customCommands,
|
||||||
Loaders: Loaders{
|
Loaders: Loaders{
|
||||||
Commits: loaders.NewCommitLoader(cmn, cmd, dotGitDir, branchCommands.CurrentBranchName, statusCommands.RebaseMode),
|
Commits: loaders.NewCommitLoader(cmn, cmd, dotGitDir, branchCommands.CurrentBranchName, statusCommands.RebaseMode),
|
||||||
Branches: loaders.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchName),
|
Branches: loaders.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchName),
|
||||||
|
@ -225,10 +225,12 @@ func (self *RebaseCommands) MoveTodoDown(index int) error {
|
|||||||
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
|
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
|
||||||
func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error {
|
func (self *RebaseCommands) SquashAllAboveFixupCommits(sha string) error {
|
||||||
return self.runSkipEditorCommand(
|
return self.runSkipEditorCommand(
|
||||||
|
self.cmd.New(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"git rebase --interactive --autostash --autosquash %s^",
|
"git rebase --interactive --autostash --autosquash %s^",
|
||||||
sha,
|
sha,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,16 +271,14 @@ func (self *RebaseCommands) RebaseBranch(branchName string) error {
|
|||||||
return cmdObj.Run()
|
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"
|
// 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
|
// By default we skip the editor in the case where a commit will be made
|
||||||
func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, command string) error {
|
func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, command string) error {
|
||||||
err := self.runSkipEditorCommand(
|
err := self.runSkipEditorCommand(self.GenericMergeOrRebaseActionCmdObj(commandType, command))
|
||||||
fmt.Sprintf(
|
|
||||||
"git %s --%s",
|
|
||||||
commandType,
|
|
||||||
command,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.Contains(err.Error(), "no rebase in progress") {
|
if !strings.Contains(err.Error(), "no rebase in progress") {
|
||||||
return err
|
return err
|
||||||
@ -300,8 +300,7 @@ func (self *RebaseCommands) GenericMergeOrRebaseAction(commandType string, comma
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RebaseCommands) runSkipEditorCommand(command string) error {
|
func (self *RebaseCommands) runSkipEditorCommand(cmdObj oscommands.ICmdObj) error {
|
||||||
cmdObj := self.cmd.New(command)
|
|
||||||
lazyGitPath := oscommands.GetLazygitPath()
|
lazyGitPath := oscommands.GetLazygitPath()
|
||||||
return cmdObj.
|
return cmdObj.
|
||||||
AddEnvVars(
|
AddEnvVars(
|
||||||
|
@ -203,7 +203,7 @@ func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run and save output
|
// Run and save output
|
||||||
message, err := gui.GitCommand.Cmd.New(cmdStr).RunWithOutput()
|
message, err := gui.GitCommand.Custom.RunWithOutput(cmdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,6 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"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 {
|
func (gui *Gui) handleCreateGitFlowMenu() error {
|
||||||
branch := gui.getSelectedBranch()
|
branch := gui.getSelectedBranch()
|
||||||
if branch == nil {
|
if branch == nil {
|
||||||
@ -70,3 +60,13 @@ func (gui *Gui) handleCreateGitFlowMenu() error {
|
|||||||
|
|
||||||
return gui.createMenu("git flow", menuItems, createMenuOptions{})
|
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)
|
||||||
|
}
|
||||||
|
@ -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
|
// 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 {
|
if status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && gui.UserConfig.Git.Merging.ManualCommit {
|
||||||
sub := gui.GitCommand.Cmd.New("git " + commandType + " --" + command)
|
// TODO: see if we should be calling more of the code from gui.GitCommand.Rebase.GenericMergeOrRebaseAction
|
||||||
if sub != nil {
|
return gui.runSubprocessWithSuspenseAndRefresh(
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(sub)
|
gui.GitCommand.Rebase.GenericMergeOrRebaseActionCmdObj(commandType, command),
|
||||||
}
|
)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
result := gui.GitCommand.Rebase.GenericMergeOrRebaseAction(commandType, command)
|
result := gui.GitCommand.Rebase.GenericMergeOrRebaseAction(commandType, command)
|
||||||
if err := gui.handleGenericMergeCommandResult(result); err != nil {
|
if err := gui.handleGenericMergeCommandResult(result); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user