1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/git_flow.go
Jesse Duffield 364c5db19c shorten name
2022-01-09 14:09:53 +11:00

73 lines
1.7 KiB
Go

package gui
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/utils"
)
func (gui *Gui) handleCreateGitFlowMenu() error {
branch := gui.getSelectedBranch()
if branch == nil {
return nil
}
if !gui.Git.Flow.GitFlowEnabled() {
return gui.createErrorPanel("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.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType})
return gui.prompt(promptOpts{
title: title,
handleConfirm: func(name string) error {
gui.logAction(gui.Tr.Actions.GitFlowStart)
return gui.runSubprocessWithSuspenseAndRefresh(
gui.Git.Flow.StartCmdObj(branchType, name),
)
},
})
}
}
menuItems := []*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"),
},
}
return gui.createMenu("git flow", menuItems, createMenuOptions{})
}
func (gui *Gui) gitFlowFinishBranch(branchName string) error {
cmdObj, err := gui.Git.Flow.FinishCmdObj(branchName)
if err != nil {
return gui.surfaceError(err)
}
gui.logAction(gui.Tr.Actions.GitFlowFinish)
return gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
}