summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-07 19:56:33 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-09 14:09:53 +1100
commit610e503296b36ef1d0551c957a6c593fae4cd60c (patch)
tree9b74b09e4dd6279072d1a95cbc6eda1d46de8429 /pkg/commands
parente92076d2c299c8171e972171c174261c6ce62d3b (diff)
refactor git flow
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/config.go4
-rw-r--r--pkg/commands/flow.go64
-rw-r--r--pkg/commands/git.go3
-rw-r--r--pkg/commands/git_config/get_key.go5
4 files changed, 74 insertions, 2 deletions
diff --git a/pkg/commands/config.go b/pkg/commands/config.go
index 52eb82ac3..c5f56c7b4 100644
--- a/pkg/commands/config.go
+++ b/pkg/commands/config.go
@@ -93,3 +93,7 @@ func (self *ConfigCommands) Branches() (map[string]*config.Branch, error) {
return conf.Branches, nil
}
+
+func (self *ConfigCommands) GetGitFlowPrefixes() string {
+ return self.gitConfig.Get("--local --get-regexp gitflow.prefix.")
+}
diff --git a/pkg/commands/flow.go b/pkg/commands/flow.go
new file mode 100644
index 000000000..9506a7e85
--- /dev/null
+++ b/pkg/commands/flow.go
@@ -0,0 +1,64 @@
+package commands
+
+import (
+ "regexp"
+ "strings"
+
+ "github.com/go-errors/errors"
+ "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/common"
+)
+
+type FlowCommands struct {
+ *common.Common
+
+ config *ConfigCommands
+ cmd oscommands.ICmdObjBuilder
+}
+
+func NewFlowCommands(
+ common *common.Common,
+ cmd oscommands.ICmdObjBuilder,
+ config *ConfigCommands,
+) *FlowCommands {
+ return &FlowCommands{
+ Common: common,
+ cmd: cmd,
+ config: config,
+ }
+}
+
+func (self *FlowCommands) GitFlowEnabled() bool {
+ return self.config.GetGitFlowPrefixes() == ""
+}
+
+func (self *FlowCommands) FinishCmdObj(branchName string) (oscommands.ICmdObj, error) {
+ prefixes := self.config.GetGitFlowPrefixes()
+
+ // 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(prefixes), "\n") {
+ if strings.HasPrefix(line, "gitflow.prefix.") && strings.HasSuffix(line, prefix) {
+ 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 nil, errors.New(self.Tr.NotAGitFlowBranch)
+ }
+
+ return self.cmd.New("git flow " + branchType + " finish " + suffix), nil
+}
+
+func (self *FlowCommands) StartCmdObj(branchType string, name string) oscommands.ICmdObj {
+ return self.cmd.New("git flow " + branchType + " start " + name)
+}
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index f9dd0c8a4..4ca2631cf 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -37,6 +37,7 @@ type GitCommand struct {
Patch *PatchCommands
Remote *RemoteCommands
Sync *SyncCommands
+ Flow *FlowCommands
}
type Loaders struct {
@@ -94,6 +95,7 @@ func NewGitCommandAux(
configCommands := NewConfigCommands(cmn, gitConfig)
statusCommands := NewStatusCommands(cmn, osCommand, repo, dotGitDir)
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
+ flowCommands := NewFlowCommands(cmn, cmd, configCommands)
remoteCommands := NewRemoteCommands(cmn, cmd)
branchCommands := NewBranchCommands(cmn, cmd)
syncCommands := NewSyncCommands(cmn, cmd)
@@ -132,6 +134,7 @@ func NewGitCommandAux(
Patch: patchCommands,
Remote: remoteCommands,
Sync: syncCommands,
+ Flow: flowCommands,
Loaders: Loaders{
Commits: loaders.NewCommitLoader(cmn, cmd, dotGitDir, branchCommands.CurrentBranchName, statusCommands.RebaseMode),
Branches: loaders.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchName),
diff --git a/pkg/commands/git_config/get_key.go b/pkg/commands/git_config/get_key.go
index 85892ea2d..4ad5ae63e 100644
--- a/pkg/commands/git_config/get_key.go
+++ b/pkg/commands/git_config/get_key.go
@@ -36,7 +36,8 @@ import (
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
func getGitConfigValue(key string) (string, error) {
- gitArgs := []string{"config", "--get", "--null", key}
+ // allowing caller to say that key is '--local mykey' so that they can add extra flags.
+ gitArgs := append([]string{"config", "--get", "--null"}, strings.Split(key, " ")...)
var stdout bytes.Buffer
cmd := secureexec.Command("git", gitArgs...)
cmd.Stdout = &stdout
@@ -46,7 +47,7 @@ func getGitConfigValue(key string) (string, error) {
if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 {
- return "", fmt.Errorf("the key `%s` is not found", key)
+ return "", fmt.Errorf("the key is not found for %s", cmd.Args)
}
}
return "", err