1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00
lazygit/pkg/gui/git_flow.go

75 lines
1.8 KiB
Go
Raw Normal View History

2020-01-07 21:42:33 +11:00
package gui
import (
"fmt"
2022-01-29 19:09:20 +11:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
2020-10-04 11:00:48 +11:00
"github.com/jesseduffield/lazygit/pkg/utils"
2020-01-07 21:42:33 +11:00
)
func (gui *Gui) handleCreateGitFlowMenu() error {
2020-01-07 21:42:33 +11:00
branch := gui.getSelectedBranch()
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")
2020-01-07 21:42:33 +11:00
}
startHandler := func(branchType string) func() error {
return func() error {
title := utils.ResolvePlaceholderString(gui.c.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType})
2020-11-28 13:35:58 +11:00
2022-01-29 19:09:20 +11:00
return gui.c.Prompt(types.PromptOpts{
2022-01-28 20:44:36 +11:00
Title: title,
HandleConfirm: func(name string) error {
gui.c.LogAction(gui.c.Tr.Actions.GitFlowStart)
2021-04-10 11:40:42 +10:00
return gui.runSubprocessWithSuspenseAndRefresh(
gui.git.Flow.StartCmdObj(branchType, name),
)
2020-11-28 13:35:58 +11:00
},
2020-01-07 21:42:33 +11:00
})
}
}
2022-01-29 19:09:20 +11:00
return gui.c.Menu(types.CreateMenuOptions{
2022-01-28 20:44:36 +11:00
Title: "git flow",
2022-01-29 19:09:20 +11:00
Items: []*types.MenuItem{
2022-01-28 20:44:36 +11:00
{
// 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"),
2020-01-07 21:42:33 +11:00
},
},
2022-01-28 20:44:36 +11:00
})
2020-01-07 21:42:33 +11:00
}
2022-01-07 20:33:34 +11:00
func (gui *Gui) gitFlowFinishBranch(branchName string) error {
cmdObj, err := gui.git.Flow.FinishCmdObj(branchName)
2022-01-07 20:33:34 +11:00
if err != nil {
return gui.c.Error(err)
2022-01-07 20:33:34 +11:00
}
gui.c.LogAction(gui.c.Tr.Actions.GitFlowFinish)
2022-01-07 20:33:34 +11:00
return gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
}