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

73 lines
1.7 KiB
Go
Raw Normal View History

2020-01-07 12:42:33 +02:00
package gui
import (
"fmt"
2020-10-04 02:00:48 +02:00
"github.com/jesseduffield/lazygit/pkg/utils"
2020-01-07 12:42:33 +02:00
)
func (gui *Gui) handleCreateGitFlowMenu() error {
2020-01-07 12:42:33 +02:00
branch := gui.getSelectedBranch()
if branch == nil {
return nil
}
2022-01-08 05:10:01 +02:00
if !gui.Git.Flow.GitFlowEnabled() {
2020-03-28 02:47:54 +02:00
return gui.createErrorPanel("You need to install git-flow and enable it in this repo to use git-flow features")
2020-01-07 12:42:33 +02:00
}
startHandler := func(branchType string) func() error {
return func() error {
2020-10-04 02:00:48 +02:00
title := utils.ResolvePlaceholderString(gui.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType})
2020-11-28 04:35:58 +02:00
return gui.prompt(promptOpts{
title: title,
handleConfirm: func(name string) error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.GitFlowStart)
2021-04-10 03:40:42 +02:00
return gui.runSubprocessWithSuspenseAndRefresh(
2022-01-08 05:10:01 +02:00
gui.Git.Flow.StartCmdObj(branchType, name),
)
2020-11-28 04:35:58 +02:00
},
2020-01-07 12:42:33 +02:00
})
}
}
2020-02-14 14:35:01 +02:00
menuItems := []*menuItem{
2020-01-07 12:42:33 +02:00
{
// not localising here because it's one to one with the actual git flow commands
2020-02-14 14:35:01 +02:00
displayString: fmt.Sprintf("finish branch '%s'", branch.Name),
onPress: func() error {
2022-01-07 10:56:33 +02:00
return gui.gitFlowFinishBranch(branch.Name)
2020-01-07 12:42:33 +02:00
},
},
{
2020-02-14 14:35:01 +02:00
displayString: "start feature",
onPress: startHandler("feature"),
2020-01-07 12:42:33 +02:00
},
{
2020-02-14 14:35:01 +02:00
displayString: "start hotfix",
onPress: startHandler("hotfix"),
2020-01-07 12:42:33 +02:00
},
2020-04-20 10:20:10 +02:00
{
displayString: "start bugfix",
onPress: startHandler("bugfix"),
},
2020-01-07 12:42:33 +02:00
{
2020-02-14 14:35:01 +02:00
displayString: "start release",
onPress: startHandler("release"),
2020-01-07 12:42:33 +02:00
},
}
2020-02-14 14:39:02 +02:00
return gui.createMenu("git flow", menuItems, createMenuOptions{})
2020-01-07 12:42:33 +02:00
}
2022-01-07 11:33:34 +02:00
func (gui *Gui) gitFlowFinishBranch(branchName string) error {
2022-01-08 05:10:01 +02:00
cmdObj, err := gui.Git.Flow.FinishCmdObj(branchName)
2022-01-07 11:33:34 +02:00
if err != nil {
return gui.surfaceError(err)
}
gui.logAction(gui.Tr.Actions.GitFlowFinish)
return gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
}