diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-02-13 18:12:21 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | e842d1bc9e2db9436fe968a9fad7aacca78570ea (patch) | |
tree | 8364aa7debc7e259d257f01567e32d7834b5b254 /pkg | |
parent | 8a555dd62ebdb985041f421dca650b941007afc1 (diff) |
move git flow
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/controllers/git_flow_controller.go | 119 | ||||
-rw-r--r-- | pkg/gui/git_flow.go | 74 | ||||
-rw-r--r-- | pkg/gui/gui.go | 3 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 8 |
4 files changed, 121 insertions, 83 deletions
diff --git a/pkg/gui/controllers/git_flow_controller.go b/pkg/gui/controllers/git_flow_controller.go new file mode 100644 index 000000000..a6d8f1da4 --- /dev/null +++ b/pkg/gui/controllers/git_flow_controller.go @@ -0,0 +1,119 @@ +package controllers + +import ( + "fmt" + + "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +type GitFlowController struct { + baseController + *controllerCommon +} + +var _ types.IController = &GitFlowController{} + +func NewGitFlowController( + common *controllerCommon, +) *GitFlowController { + return &GitFlowController{ + baseController: baseController{}, + controllerCommon: common, + } +} + +func (self *GitFlowController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + bindings := []*types.Binding{ + { + Key: opts.GetKey(opts.Config.Branches.ViewGitFlowOptions), + Handler: self.checkSelected(self.handleCreateGitFlowMenu), + Description: self.c.Tr.LcGitFlowOptions, + OpensMenu: true, + }, + } + + return bindings +} + +func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) error { + if !self.git.Flow.GitFlowEnabled() { + return self.c.ErrorMsg("You need to install git-flow and enable it in this repo to use git-flow features") + } + + startHandler := func(branchType string) func() error { + return func() error { + title := utils.ResolvePlaceholderString(self.c.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType}) + + return self.c.Prompt(types.PromptOpts{ + Title: title, + HandleConfirm: func(name string) error { + self.c.LogAction(self.c.Tr.Actions.GitFlowStart) + return self.c.RunSubprocessAndRefresh( + self.git.Flow.StartCmdObj(branchType, name), + ) + }, + }) + } + } + + return self.c.Menu(types.CreateMenuOptions{ + Title: "git flow", + Items: []*types.MenuItem{ + { + // not localising here because it's one to one with the actual git flow commands + DisplayString: fmt.Sprintf("finish branch '%s'", branch.Name), + OnPress: func() error { + return self.gitFlowFinishBranch(branch.Name) + }, + }, + { + DisplayString: "start feature", + OnPress: startHandler("feature"), + }, + { + DisplayString: "start hotfix", + OnPress: startHandler("hotfix"), + }, + { + DisplayString: "start bugfix", + OnPress: startHandler("bugfix"), + }, + { + DisplayString: "start release", + OnPress: startHandler("release"), + }, + }, + }) +} + +func (self *GitFlowController) gitFlowFinishBranch(branchName string) error { + cmdObj, err := self.git.Flow.FinishCmdObj(branchName) + if err != nil { + return self.c.Error(err) + } + + self.c.LogAction(self.c.Tr.Actions.GitFlowFinish) + return self.c.RunSubprocessAndRefresh(cmdObj) +} + +func (self *GitFlowController) checkSelected(callback func(*models.Branch) error) func() error { + return func() error { + node := self.context().GetSelected() + if node == nil { + return nil + } + + return callback(node) + } +} + +func (self *GitFlowController) Context() types.Context { + return self.context() +} + +func (self *GitFlowController) context() *context.BranchesContext { + return self.contexts.Branches +} diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go deleted file mode 100644 index c26b94a70..000000000 --- a/pkg/gui/git_flow.go +++ /dev/null @@ -1,74 +0,0 @@ -package gui - -import ( - "fmt" - - "github.com/jesseduffield/lazygit/pkg/gui/types" - "github.com/jesseduffield/lazygit/pkg/utils" -) - -func (gui *Gui) handleCreateGitFlowMenu() error { - branch := gui.State.Contexts.Branches.GetSelected() - if branch == nil { - return nil - } - - if !gui.git.Flow.GitFlowEnabled() { - return gui.c.ErrorMsg("You need to install git-flow and enable it in this repo to use git-flow features") - } - - startHandler := func(branchType string) func() error { - return func() error { - title := utils.ResolvePlaceholderString(gui.c.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType}) - - return gui.c.Prompt(types.PromptOpts{ - Title: title, - HandleConfirm: func(name string) error { - gui.c.LogAction(gui.c.Tr.Actions.GitFlowStart) - return gui.runSubprocessWithSuspenseAndRefresh( - gui.git.Flow.StartCmdObj(branchType, name), - ) - }, - }) - } - } - - return gui.c.Menu(types.CreateMenuOptions{ - Title: "git flow", - Items: []*types.MenuItem{ - { - // not localising here because it's one to one with the actual git flow commands - DisplayString: fmt.Sprintf("finish branch '%s'", branch.Name), - OnPress: func() error { - return gui.gitFlowFinishBranch(branch.Name) - }, - }, - { - DisplayString: "start feature", - OnPress: startHandler("feature"), - }, - { - DisplayString: "start hotfix", - OnPress: startHandler("hotfix"), - }, - { - DisplayString: "start bugfix", - OnPress: startHandler("bugfix"), - }, - { - DisplayString: "start release", - OnPress: startHandler("release"), - }, - }, - }) -} - -func (gui *Gui) gitFlowFinishBranch(branchName string) error { - cmdObj, err := gui.git.Flow.FinishCmdObj(branchName) - if err != nil { - return gui.c.Error(err) - } - - gui.c.LogAction(gui.c.Tr.Actions.GitFlowFinish) - return gui.runSubprocessWithSuspenseAndRefresh(cmdObj) -} diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 069d8a5a7..77b406e6f 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -564,6 +564,7 @@ func (gui *Gui) resetControllers() { } branchesController := controllers.NewBranchesController(common) + gitFlowController := controllers.NewGitFlowController(common) filesRemoveController := controllers.NewFilesRemoveController(common) switchToSubCommitsControllerFactory := controllers.NewSubCommitsSwitchControllerFactory( @@ -592,7 +593,7 @@ func (gui *Gui) resetControllers() { controllers.AttachControllers(context, commonCommitControllerFactory.Create(context)) } - controllers.AttachControllers(gui.State.Contexts.Branches, branchesController) + controllers.AttachControllers(gui.State.Contexts.Branches, branchesController, gitFlowController) controllers.AttachControllers(gui.State.Contexts.Files, gui.Controllers.Files, filesRemoveController) controllers.AttachControllers(gui.State.Contexts.Tags, gui.Controllers.Tags) controllers.AttachControllers(gui.State.Contexts.Submodules, gui.Controllers.Submodules) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index c6b1cee82..9d278aa2d 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -383,14 +383,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi { ViewName: "branches", Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, - Key: opts.GetKey(opts.Config.Branches.ViewGitFlowOptions), - Handler: self.handleCreateGitFlowMenu, - Description: self.c.Tr.LcGitFlowOptions, - OpensMenu: true, - }, - { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, Key: opts.GetKey(opts.Config.Universal.CopyToClipboard), Handler: self.handleCopySelectedSideContextItemToClipboard, Description: self.c.Tr.LcCopyBranchNameToClipboard, |