diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-07 19:56:33 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-09 14:09:53 +1100 |
commit | 610e503296b36ef1d0551c957a6c593fae4cd60c (patch) | |
tree | 9b74b09e4dd6279072d1a95cbc6eda1d46de8429 /pkg/gui/git_flow.go | |
parent | e92076d2c299c8171e972171c174261c6ce62d3b (diff) |
refactor git flow
Diffstat (limited to 'pkg/gui/git_flow.go')
-rw-r--r-- | pkg/gui/git_flow.go | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go index 61acffbb0..959f22788 100644 --- a/pkg/gui/git_flow.go +++ b/pkg/gui/git_flow.go @@ -2,39 +2,18 @@ package gui import ( "fmt" - "regexp" - "strings" "github.com/jesseduffield/lazygit/pkg/utils" ) -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.Tr.NotAGitFlowBranch) +func (gui *Gui) gitFlowFinishBranch(branchName string) error { + cmdObj, err := gui.GitCommand.Flow.FinishCmdObj(branchName) + if err != nil { + return gui.surfaceError(err) } gui.logAction(gui.Tr.Actions.GitFlowFinish) - return gui.runSubprocessWithSuspenseAndRefresh( - gui.GitCommand.Cmd.New("git flow " + branchType + " finish " + suffix), - ) + return gui.runSubprocessWithSuspenseAndRefresh(cmdObj) } func (gui *Gui) handleCreateGitFlowMenu() error { @@ -43,9 +22,7 @@ func (gui *Gui) handleCreateGitFlowMenu() error { return nil } - // get config - gitFlowConfig, err := gui.GitCommand.Cmd.New("git config --local --get-regexp gitflow").RunWithOutput() - if err != nil { + if !gui.GitCommand.Flow.GitFlowEnabled() { return gui.createErrorPanel("You need to install git-flow and enable it in this repo to use git-flow features") } @@ -58,7 +35,7 @@ func (gui *Gui) handleCreateGitFlowMenu() error { handleConfirm: func(name string) error { gui.logAction(gui.Tr.Actions.GitFlowStart) return gui.runSubprocessWithSuspenseAndRefresh( - gui.GitCommand.Cmd.New("git flow " + branchType + " start " + name), + gui.GitCommand.Flow.StartCmdObj(branchType, name), ) }, }) @@ -70,7 +47,7 @@ func (gui *Gui) handleCreateGitFlowMenu() error { // 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(gitFlowConfig, branch.Name) + return gui.gitFlowFinishBranch(branch.Name) }, }, { |