mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-10 20:05:50 +02:00
Centralize logic regarding WorkingTreeState close to its definition
This commit is contained in:
parent
cd36e95a82
commit
b210b4363d
6 changed files with 52 additions and 64 deletions
|
@ -1,5 +1,7 @@
|
|||
package enums
|
||||
|
||||
import "github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
|
||||
type WorkingTreeState int
|
||||
|
||||
const (
|
||||
|
@ -16,3 +18,46 @@ func (self WorkingTreeState) IsMerging() bool {
|
|||
func (self WorkingTreeState) IsRebasing() bool {
|
||||
return self == WORKING_TREE_STATE_REBASING
|
||||
}
|
||||
|
||||
func (self WorkingTreeState) Title(tr *i18n.TranslationSet) string {
|
||||
switch self {
|
||||
case WORKING_TREE_STATE_REBASING:
|
||||
return tr.RebasingStatus
|
||||
case WORKING_TREE_STATE_MERGING:
|
||||
return tr.MergingStatus
|
||||
default:
|
||||
// should never actually display this
|
||||
return "none"
|
||||
}
|
||||
}
|
||||
|
||||
func (self WorkingTreeState) LowerCaseTitle(tr *i18n.TranslationSet) string {
|
||||
switch self {
|
||||
case WORKING_TREE_STATE_REBASING:
|
||||
return tr.LowercaseRebasingStatus
|
||||
case WORKING_TREE_STATE_MERGING:
|
||||
return tr.LowercaseMergingStatus
|
||||
default:
|
||||
// should never actually display this
|
||||
return "none"
|
||||
}
|
||||
}
|
||||
|
||||
func (self WorkingTreeState) OptionsMenuTitle(tr *i18n.TranslationSet) string {
|
||||
if self == WORKING_TREE_STATE_MERGING {
|
||||
return tr.MergeOptionsTitle
|
||||
}
|
||||
return tr.RebaseOptionsTitle
|
||||
}
|
||||
|
||||
func (self WorkingTreeState) CommandName() string {
|
||||
switch self {
|
||||
case WORKING_TREE_STATE_MERGING:
|
||||
return "merge"
|
||||
case WORKING_TREE_STATE_REBASING:
|
||||
return "rebase"
|
||||
default:
|
||||
// shouldn't be possible to land here
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,13 +67,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
|
|||
}
|
||||
})
|
||||
|
||||
var title string
|
||||
if self.c.Git().Status.WorkingTreeState() == enums.WORKING_TREE_STATE_MERGING {
|
||||
title = self.c.Tr.MergeOptionsTitle
|
||||
} else {
|
||||
title = self.c.Tr.RebaseOptionsTitle
|
||||
}
|
||||
|
||||
title := self.c.Git().Status.WorkingTreeState().OptionsMenuTitle(self.c.Tr)
|
||||
return self.c.Menu(types.CreateMenuOptions{Title: title, Items: menuItems})
|
||||
}
|
||||
|
||||
|
@ -103,15 +97,7 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
|
|||
}
|
||||
}
|
||||
|
||||
commandType := ""
|
||||
switch status {
|
||||
case enums.WORKING_TREE_STATE_MERGING:
|
||||
commandType = "merge"
|
||||
case enums.WORKING_TREE_STATE_REBASING:
|
||||
commandType = "rebase"
|
||||
default:
|
||||
// shouldn't be possible to land here
|
||||
}
|
||||
commandType := status.CommandName()
|
||||
|
||||
// we should end up with a command like 'git merge --continue'
|
||||
|
||||
|
@ -199,7 +185,7 @@ func (self *MergeAndRebaseHelper) CheckForConflicts(result error) error {
|
|||
}
|
||||
|
||||
func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
|
||||
mode := self.workingTreeStateNoun()
|
||||
mode := self.c.Git().Status.WorkingTreeState().CommandName()
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.FoundConflictsTitle,
|
||||
Items: []*types.MenuItem{
|
||||
|
@ -224,7 +210,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
|
|||
|
||||
func (self *MergeAndRebaseHelper) AbortMergeOrRebaseWithConfirm() error {
|
||||
// prompt user to confirm that they want to abort, then do it
|
||||
mode := self.workingTreeStateNoun()
|
||||
mode := self.c.Git().Status.WorkingTreeState().CommandName()
|
||||
self.c.Confirm(types.ConfirmOpts{
|
||||
Title: fmt.Sprintf(self.c.Tr.AbortTitle, mode),
|
||||
Prompt: fmt.Sprintf(self.c.Tr.AbortPrompt, mode),
|
||||
|
@ -236,18 +222,6 @@ func (self *MergeAndRebaseHelper) AbortMergeOrRebaseWithConfirm() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *MergeAndRebaseHelper) workingTreeStateNoun() string {
|
||||
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
||||
switch workingTreeState {
|
||||
case enums.WORKING_TREE_STATE_NONE:
|
||||
return ""
|
||||
case enums.WORKING_TREE_STATE_MERGING:
|
||||
return "merge"
|
||||
default:
|
||||
return "rebase"
|
||||
}
|
||||
}
|
||||
|
||||
// PromptToContinueRebase asks the user if they want to continue the rebase/merge that's in progress
|
||||
func (self *MergeAndRebaseHelper) PromptToContinueRebase() error {
|
||||
self.c.Confirm(types.ConfirmOpts{
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
|
@ -121,7 +120,7 @@ func (self *ModeHelper) Statuses() []ModeStatus {
|
|||
Description: func() string {
|
||||
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
||||
return self.withResetButton(
|
||||
presentation.FormatWorkingTreeStateTitle(self.c.Tr, workingTreeState), style.FgYellow,
|
||||
workingTreeState.Title(self.c.Tr), style.FgYellow,
|
||||
)
|
||||
},
|
||||
Reset: self.mergeAndRebaseHelper.AbortMergeOrRebaseWithConfirm,
|
||||
|
|
|
@ -111,7 +111,7 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
|||
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
||||
switch workingTreeState {
|
||||
case enums.WORKING_TREE_STATE_REBASING, enums.WORKING_TREE_STATE_MERGING:
|
||||
workingTreeStatus := fmt.Sprintf("(%s)", presentation.FormatWorkingTreeStateLower(self.c.Tr, workingTreeState))
|
||||
workingTreeStatus := fmt.Sprintf("(%s)", workingTreeState.LowerCaseTitle(self.c.Tr))
|
||||
if cursorInSubstring(opts.X, upstreamStatus+" ", workingTreeStatus) {
|
||||
return self.c.Helpers().MergeAndRebase.CreateRebaseOptionsMenu()
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func FormatStatus(
|
|||
}
|
||||
|
||||
if workingTreeState != enums.WORKING_TREE_STATE_NONE {
|
||||
status += style.FgYellow.Sprintf("(%s) ", FormatWorkingTreeStateLower(tr, workingTreeState))
|
||||
status += style.FgYellow.Sprintf("(%s) ", workingTreeState.LowerCaseTitle(tr))
|
||||
}
|
||||
|
||||
name := GetBranchTextStyle(currentBranch.Name).Sprint(currentBranch.Name)
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package presentation
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
)
|
||||
|
||||
func FormatWorkingTreeStateTitle(tr *i18n.TranslationSet, workingTreeState enums.WorkingTreeState) string {
|
||||
switch workingTreeState {
|
||||
case enums.WORKING_TREE_STATE_REBASING:
|
||||
return tr.RebasingStatus
|
||||
case enums.WORKING_TREE_STATE_MERGING:
|
||||
return tr.MergingStatus
|
||||
default:
|
||||
// should never actually display this
|
||||
return "none"
|
||||
}
|
||||
}
|
||||
|
||||
func FormatWorkingTreeStateLower(tr *i18n.TranslationSet, workingTreeState enums.WorkingTreeState) string {
|
||||
switch workingTreeState {
|
||||
case enums.WORKING_TREE_STATE_REBASING:
|
||||
return tr.LowercaseRebasingStatus
|
||||
case enums.WORKING_TREE_STATE_MERGING:
|
||||
return tr.LowercaseMergingStatus
|
||||
default:
|
||||
// should never actually display this
|
||||
return "none"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue