1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

better typing for rebase mode

This commit is contained in:
Jesse Duffield
2021-12-30 12:10:09 +11:00
parent 9d4ff6b465
commit 1fc0d786ae
4 changed files with 20 additions and 11 deletions

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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