summaryrefslogtreecommitdiffstats
path: root/pkg/gui/git_flow.go
blob: c26b94a709095e5bdc9c089ef31a2f8681e76100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gui

import (
	"fmt"

	"github.com/jesseduffield/lazygit/pkg/gui/types"
	"github.com/jesseduffield/lazygit/pkg/utils"
)

func (gui *Gui) handleCreateGitFlowMenu() error {
	branch := gui.State.Contexts.Branches.GetSelected()
	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")
	}

	startHandler := func(branchType string) func() error {
		return func() error {
			title := utils.ResolvePlaceholderString(gui.c.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType})

			return gui.c.Prompt(types.PromptOpts{
				Title: title,
				HandleConfirm: func(name string) error {
					gui.c.LogAction(gui.c.Tr.Actions.GitFlowStart)
					return gui.runSubprocessWithSuspenseAndRefresh(
						gui.git.Flow.StartCmdObj(branchType, name),
					)
				},
			})
		}
	}

	return gui.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
				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"),
			},
		},
	})
}

func (gui *Gui) gitFlowFinishBranch(branchName string) error {
	cmdObj, err := gui.git.Flow.FinishCmdObj(branchName)
	if err != nil {
		return gui.c.Error(err)
	}

	gui.c.LogAction(gui.c.Tr.Actions.GitFlowFinish)
	return gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
}