summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-12-30 12:10:09 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-04 09:07:15 +1100
commit1fc0d786aef2e3c0e1ccfe3f33f22dbafbbda87f (patch)
tree1e93685cd77b7fd577cf2b7ed29cfac300230f64 /pkg/commands
parent9d4ff6b46512aa5261ab6218d978737a0b33359d (diff)
better typing for rebase mode
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/loading_commits.go6
-rw-r--r--pkg/commands/status.go14
2 files changed, 11 insertions, 9 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