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:
@ -32,7 +32,7 @@ type CommitListBuilder struct {
|
|||||||
cmd oscommands.ICmdObjBuilder
|
cmd oscommands.ICmdObjBuilder
|
||||||
|
|
||||||
getCurrentBranchName func() (string, string, error)
|
getCurrentBranchName func() (string, string, error)
|
||||||
getRebaseMode func() (string, error)
|
getRebaseMode func() (RebaseMode, error)
|
||||||
readFile func(filename string) ([]byte, error)
|
readFile func(filename string) ([]byte, error)
|
||||||
walkFiles func(root string, fn filepath.WalkFunc) error
|
walkFiles func(root string, fn filepath.WalkFunc) error
|
||||||
dotGitDir string
|
dotGitDir string
|
||||||
@ -186,7 +186,7 @@ func (self *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Com
|
|||||||
return commits, nil
|
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)
|
commits, err := self.getRebasingCommits(rebaseMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// 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 {
|
switch rebaseMode {
|
||||||
case REBASE_MODE_MERGING:
|
case REBASE_MODE_MERGING:
|
||||||
return self.getNormalRebasingCommits()
|
return self.getNormalRebasingCommits()
|
||||||
|
@ -6,8 +6,10 @@ import (
|
|||||||
gogit "github.com/jesseduffield/go-git/v5"
|
gogit "github.com/jesseduffield/go-git/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RebaseMode string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
REBASE_MODE_NORMAL = "normal"
|
REBASE_MODE_NORMAL RebaseMode = "normal"
|
||||||
REBASE_MODE_INTERACTIVE = "interactive"
|
REBASE_MODE_INTERACTIVE = "interactive"
|
||||||
REBASE_MODE_REBASING = "rebasing"
|
REBASE_MODE_REBASING = "rebasing"
|
||||||
REBASE_MODE_MERGING = "merging"
|
REBASE_MODE_MERGING = "merging"
|
||||||
@ -15,7 +17,7 @@ const (
|
|||||||
|
|
||||||
// RebaseMode returns "" for non-rebase mode, "normal" for normal rebase
|
// RebaseMode returns "" for non-rebase mode, "normal" for normal rebase
|
||||||
// and "interactive" for interactive 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"))
|
exists, err := c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "rebase-apply"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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()
|
rebaseMode, _ := c.RebaseMode()
|
||||||
if rebaseMode != "" {
|
if rebaseMode != "" {
|
||||||
return REBASE_MODE_REBASING
|
return REBASE_MODE_REBASING
|
||||||
|
@ -53,7 +53,14 @@ func (gui *Gui) genericMergeCommand(command string) error {
|
|||||||
|
|
||||||
gitCommand := gui.GitCommand.WithSpan(fmt.Sprintf("Merge/Rebase: %s", command))
|
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'
|
// 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
|
// it's impossible for a rebase to require a commit so we'll use a subprocess only if it's a merge
|
||||||
|
@ -157,7 +157,7 @@ func lazygitTitle() string {
|
|||||||
|___/ |___/ `
|
|___/ |___/ `
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) workingTreeState() string {
|
func (gui *Gui) workingTreeState() commands.RebaseMode {
|
||||||
rebaseMode, _ := gui.GitCommand.RebaseMode()
|
rebaseMode, _ := gui.GitCommand.RebaseMode()
|
||||||
if rebaseMode != "" {
|
if rebaseMode != "" {
|
||||||
return commands.REBASE_MODE_REBASING
|
return commands.REBASE_MODE_REBASING
|
||||||
|
Reference in New Issue
Block a user