1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00
lazygit/pkg/gui/controllers/git_flow_controller.go
Jesse Duffield d772c9f1d4 Use sentence case everywhere
We have not been good at consistent casing so far. Now we use 'Sentence case' everywhere. EVERYWHERE.

Also Removing 'Lc' prefix from i18n field names: the 'Lc' stood for lowercase but now that everything
is in 'Sentence case' there's no need for the distinction.

I've got a couple lower case things I've kept: namely, things that show up in parentheses.
2023-05-25 23:52:19 +10:00

124 lines
3.0 KiB
Go

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
c *ControllerCommon
}
var _ types.IController = &GitFlowController{}
func NewGitFlowController(
common *ControllerCommon,
) *GitFlowController {
return &GitFlowController{
baseController: baseController{},
c: 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.GitFlowOptions,
OpensMenu: true,
},
}
return bindings
}
func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) error {
if !self.c.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.c.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
Label: fmt.Sprintf("finish branch '%s'", branch.Name),
OnPress: func() error {
return self.gitFlowFinishBranch(branch.Name)
},
},
{
Label: "start feature",
OnPress: startHandler("feature"),
Key: 'f',
},
{
Label: "start hotfix",
OnPress: startHandler("hotfix"),
Key: 'h',
},
{
Label: "start bugfix",
OnPress: startHandler("bugfix"),
Key: 'b',
},
{
Label: "start release",
OnPress: startHandler("release"),
Key: 'r',
},
},
})
}
func (self *GitFlowController) gitFlowFinishBranch(branchName string) error {
cmdObj, err := self.c.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.c.Contexts().Branches
}