diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-30 12:10:09 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-04 09:07:15 +1100 |
commit | 1fc0d786aef2e3c0e1ccfe3f33f22dbafbbda87f (patch) | |
tree | 1e93685cd77b7fd577cf2b7ed29cfac300230f64 /pkg | |
parent | 9d4ff6b46512aa5261ab6218d978737a0b33359d (diff) |
better typing for rebase mode
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/loading_commits.go | 6 | ||||
-rw-r--r-- | pkg/commands/status.go | 14 | ||||
-rw-r--r-- | pkg/gui/rebase_options_panel.go | 9 | ||||
-rw-r--r-- | pkg/gui/status_panel.go | 2 |
4 files changed, 20 insertions, 11 deletions
diff --git a/pkg/commands/loading_commits.go b/pkg/commands/loading_commits.go index 48208da73..4c2d5f348 100644 --- a/pkg/commands/loading_commits.go +++ b/pkg/commands/loading_commits.go @@ -32,7 +32,7 @@ type CommitListBuilder struct { cmd oscommands.ICmdObjBuilder getCurrentBranchName func() (string, string, error) - getRebaseMode func() (string, error) + getRebaseMode func() (RebaseMode, error) readFile func(filename string) ([]byte, error) walkFiles func(root string, fn filepath.WalkFunc) error dotGitDir string @@ -186,7 +186,7 @@ func (self *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Com return commits, nil } -func (self *CommitListBuilder) getHydratedRebasingCommits(rebaseMode string) ([]*models.Commit, error) { +func (self *CommitListBuilder) getHydratedRebasingCommits(rebaseMode RebaseMode) ([]*models.Commit, error) { commits, err := self.getRebasingCommits(rebaseMode) if err != nil { return nil, err @@ -232,7 +232,7 @@ func (self *CommitListBuilder) getHydratedRebasingCommits(rebaseMode string) ([] } // getRebasingCommits obtains the commits that we're in the process of rebasing -func (self *CommitListBuilder) getRebasingCommits(rebaseMode string) ([]*models.Commit, error) { +func (self *CommitListBuilder) getRebasingCommits(rebaseMode RebaseMode) ([]*models.Commit, error) { switch rebaseMode { case REBASE_MODE_MERGING: return self.getNormalRebasingCommits() diff --git a/pkg/commands/status.go b/pkg/commands/status.go index c11fe829f..0471aca00 100644 --- a/pkg/commands/status.go +++ b/pkg/commands/status.go @@ -6,16 +6,18 @@ import ( gogit "github.com/jesseduffield/go-git/v5" ) +type RebaseMode string + const ( - REBASE_MODE_NORMAL = "normal" - REBASE_MODE_INTERACTIVE = "interactive" - REBASE_MODE_REBASING = "rebasing" - REBASE_MODE_MERGING = "merging" + REBASE_MODE_NORMAL RebaseMode = "normal" + REBASE_MODE_INTERACTIVE = "interactive" + REBASE_MODE_REBASING = "rebasing" + REBASE_MODE_MERGING = "merging" ) // RebaseMode returns "" for non-rebase mode, "normal" for normal rebase // and "interactive" for interactive rebase -func (c *GitCommand) RebaseMode() (string, error) { +func (c *GitCommand) RebaseMode() (RebaseMode, error) { exists, err := c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "rebase-apply")) if err != nil { return "", err @@ -31,7 +33,7 @@ func (c *GitCommand) RebaseMode() (string, error) { } } -func (c *GitCommand) WorkingTreeState() string { +func (c *GitCommand) WorkingTreeState() RebaseMode { rebaseMode, _ := c.RebaseMode() if rebaseMode != "" { return REBASE_MODE_REBASING diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index 205b9df92..f753fe878 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -53,7 +53,14 @@ func (gui *Gui) genericMergeCommand(command string) error { gitCommand := gui.GitCommand.WithSpan(fmt.Sprintf("Merge/Rebase: %s", command)) - commandType := strings.Replace(status, "ing", "e", 1) + commandType := "" + switch status { + case commands.REBASE_MODE_MERGING: + commandType = "merge" + case commands.REBASE_MODE_REBASING: + commandType = "rebase" + } + // we should end up with a command like 'git merge --continue' // it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index 6072db38c..4b64b0899 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -157,7 +157,7 @@ func lazygitTitle() string { |___/ |___/ ` } -func (gui *Gui) workingTreeState() string { +func (gui *Gui) workingTreeState() commands.RebaseMode { rebaseMode, _ := gui.GitCommand.RebaseMode() if rebaseMode != "" { return commands.REBASE_MODE_REBASING |