summaryrefslogtreecommitdiffstats
path: root/pkg/gui/git_flow.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-01-07 21:42:33 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-01-08 22:03:15 +1100
commit80377e47169e43a6014591d8990a6376bf5cff53 (patch)
treeded4149fdaead4738502e3f020701f39f2d17f50 /pkg/gui/git_flow.go
parentc3d54f3c2eba2be47695427f59c22844a6dba7fd (diff)
add git flow support
Diffstat (limited to 'pkg/gui/git_flow.go')
-rw-r--r--pkg/gui/git_flow.go106
1 files changed, 106 insertions, 0 deletions
diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go
new file mode 100644
index 000000000..f132f564e
--- /dev/null
+++ b/pkg/gui/git_flow.go
@@ -0,0 +1,106 @@
+package gui
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+
+ "github.com/jesseduffield/gocui"
+)
+
+type gitFlowOption struct {
+ handler func() error
+ description string
+}
+
+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 == "" {
+ return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NotAGitFlowBranch"))
+ }
+
+ subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "finish", suffix)
+ gui.SubProcess = subProcess
+ return gui.Errors.ErrSubProcess
+}
+
+// GetDisplayStrings is a function.
+func (r *gitFlowOption) GetDisplayStrings(isFocused bool) []string {
+ return []string{r.description}
+}
+
+func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error {
+ branch := gui.getSelectedBranch()
+ if branch == nil {
+ return nil
+ }
+
+ // get config
+ gitFlowConfig, err := gui.OSCommand.RunCommandWithOutput("git config --local --get-regexp gitflow")
+ if err != nil {
+ return gui.createErrorPanel(gui.g, "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 := gui.Tr.TemplateLocalize("NewBranchNamePrompt", map[string]interface{}{"branchType": branchType})
+ return gui.createPromptPanel(gui.g, gui.getMenuView(), title, "", func(g *gocui.Gui, v *gocui.View) error {
+ name := gui.trimmedContent(v)
+ subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "start", name)
+ gui.SubProcess = subProcess
+ return gui.Errors.ErrSubProcess
+ })
+ }
+ }
+
+ options := []*gitFlowOption{
+ {
+ // not localising here because it's one to one with the actual git flow commands
+ description: fmt.Sprintf("finish branch '%s'", branch.Name),
+ handler: func() error {
+ return gui.gitFlowFinishBranch(gitFlowConfig, branch.Name)
+ },
+ },
+ {
+ description: "start feature",
+ handler: startHandler("feature"),
+ },
+ {
+ description: "start hotfix",
+ handler: startHandler("hotfix"),
+ },
+ {
+ description: "start release",
+ handler: startHandler("release"),
+ },
+ {
+ description: gui.Tr.SLocalize("cancel"),
+ handler: func() error {
+ return nil
+ },
+ },
+ }
+
+ handleMenuPress := func(index int) error {
+ return options[index].handler()
+ }
+
+ return gui.createMenu("git flow", options, len(options), handleMenuPress)
+}