1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/git_flow.go

94 lines
2.5 KiB
Go
Raw Normal View History

2020-01-07 12:42:33 +02:00
package gui
import (
"fmt"
"regexp"
"strings"
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) gitFlowFinishBranch(gitFlowConfig string, branchName string) error {
// need to find out what kind of branch this is
prefix := strings.SplitAfterN(branchName, "/", 2)[0]
suffix := strings.Replace(branchName, prefix, "", 1)
branchType := ""
for _, line := range strings.Split(strings.TrimSpace(gitFlowConfig), "\n") {
if strings.HasPrefix(line, "gitflow.prefix.") && strings.HasSuffix(line, prefix) {
// now I just need to how do you say
regex := regexp.MustCompile("gitflow.prefix.([^ ]*) .*")
matches := regex.FindAllStringSubmatch(line, 1)
if len(matches) > 0 && len(matches[0]) > 1 {
branchType = matches[0][1]
break
}
}
}
if branchType == "" {
2020-10-04 02:00:48 +02:00
return gui.createErrorPanel(gui.Tr.NotAGitFlowBranch)
2020-01-07 12:42:33 +02:00
}
2021-04-10 03:40:42 +02:00
return gui.runSubprocessWithSuspenseAndRefresh(
2021-12-29 05:33:38 +02:00
gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowFinish).Cmd.New("git flow " + branchType + " finish " + suffix).Log(),
)
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
}
// get config
2021-12-29 05:33:38 +02:00
gitFlowConfig, err := gui.GitCommand.Cmd.New("git config --local --get-regexp gitflow").RunWithOutput()
2020-01-07 12:42:33 +02:00
if err != nil {
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 {
2021-04-10 03:40:42 +02:00
return gui.runSubprocessWithSuspenseAndRefresh(
2021-12-29 05:33:38 +02:00
gui.GitCommand.WithSpan(gui.Tr.Spans.GitFlowStart).Cmd.New("git flow " + branchType + " start " + name).Log(),
)
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 {
2020-01-07 12:42:33 +02:00
return gui.gitFlowFinishBranch(gitFlowConfig, branch.Name)
},
},
{
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
}