1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

refactor how we handle different modes

This commit is contained in:
Jesse Duffield 2020-08-22 11:05:37 +10:00
parent b1529f19ad
commit fbd61fcd17
13 changed files with 124 additions and 105 deletions

View File

@ -1,40 +1,52 @@
package gui
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
)
func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error {
// you can only copy from one context at a time, because the order and position of commits matter
func (gui *Gui) handleCopyCommit() error {
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
return err
}
// get currently selected commit, add the sha to state.
commit := gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx]
context := gui.currentSideContext()
if context == nil {
return nil
}
commit, ok := context.SelectedItem().(*commands.Commit)
if !ok {
gui.Log.Error("type cast failed for handling copy commit")
}
if commit == nil {
return nil
}
// we will un-copy it if it's already copied
for index, cherryPickedCommit := range gui.State.CherryPickedCommits {
for index, cherryPickedCommit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
if commit.Sha == cherryPickedCommit.Sha {
gui.State.CherryPickedCommits = append(gui.State.CherryPickedCommits[0:index], gui.State.CherryPickedCommits[index+1:]...)
return gui.Contexts.BranchCommits.Context.HandleRender()
gui.State.Modes.CherryPicking.CherryPickedCommits = append(gui.State.Modes.CherryPicking.CherryPickedCommits[0:index], gui.State.Modes.CherryPicking.CherryPickedCommits[index+1:]...)
return context.HandleRender()
}
}
gui.addCommitToCherryPickedCommits(gui.State.Panels.Commits.SelectedLineIdx)
return gui.Contexts.BranchCommits.Context.HandleRender()
return context.HandleRender()
}
func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
func (gui *Gui) CherryPickedCommitShaMap() map[string]bool {
commitShaMap := map[string]bool{}
for _, commit := range gui.State.CherryPickedCommits {
for _, commit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
commitShaMap[commit.Sha] = true
}
return commitShaMap
}
func (gui *Gui) addCommitToCherryPickedCommits(index int) {
commitShaMap := gui.cherryPickedCommitShaMap()
commitShaMap := gui.CherryPickedCommitShaMap()
commitShaMap[gui.State.Commits[index].Sha] = true
newCommits := []*commands.Commit{}
@ -45,15 +57,15 @@ func (gui *Gui) addCommitToCherryPickedCommits(index int) {
}
}
gui.State.CherryPickedCommits = newCommits
gui.State.Modes.CherryPicking.CherryPickedCommits = newCommits
}
func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) handleCopyCommitRange() error {
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
return err
}
commitShaMap := gui.cherryPickedCommitShaMap()
commitShaMap := gui.CherryPickedCommitShaMap()
// find the last commit that is copied that's above our position
// if there are none, startIndex = 0
@ -72,19 +84,19 @@ func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
}
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied
func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) HandlePasteCommits() error {
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
return err
}
return gui.ask(askOpts{
returnToView: v,
returnToView: gui.getCommitsView(),
returnFocusOnClose: true,
title: gui.Tr.SLocalize("CherryPick"),
prompt: gui.Tr.SLocalize("SureCherryPick"),
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.SLocalize("CherryPickingStatus"), func() error {
err := gui.GitCommand.CherryPickCommits(gui.State.CherryPickedCommits)
err := gui.GitCommand.CherryPickCommits(gui.State.Modes.CherryPicking.CherryPickedCommits)
return gui.handleGenericMergeCommandResult(err)
})
},

View File

@ -37,7 +37,7 @@ func (gui *Gui) handleCommitSelect() error {
task = gui.createRenderStringTask(gui.Tr.SLocalize("NoCommitsThisBranch"))
} else {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.FilterPath),
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path),
)
task = gui.createRunPtyTask(cmd)
}
@ -97,12 +97,12 @@ func (gui *Gui) refreshCommits() error {
}
func (gui *Gui) refreshCommitsWithLimit() error {
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits)
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.Modes.CherryPicking.CherryPickedCommits)
commits, err := builder.GetCommits(
commands.GetCommitsOptions{
Limit: gui.State.Panels.Commits.LimitCommits,
FilterPath: gui.State.FilterPath,
FilterPath: gui.State.Modes.Filtering.Path,
IncludeRebaseCommits: true,
RefName: "HEAD",
},
@ -555,7 +555,7 @@ func (gui *Gui) handleOpenSearchForCommitsPanel(g *gocui.Gui, v *gocui.View) err
}
func (gui *Gui) handleResetCherryPick(g *gocui.Gui, v *gocui.View) error {
gui.State.CherryPickedCommits = []*commands.Commit{}
gui.State.Modes.CherryPicking.CherryPickedCommits = []*commands.Commit{}
return gui.Contexts.BranchCommits.Context.HandleRender()
}

View File

@ -8,11 +8,11 @@ import (
)
func (gui *Gui) inDiffMode() bool {
return gui.State.Diff.Ref != ""
return gui.State.Modes.Diffing.Ref != ""
}
func (gui *Gui) exitDiffMode() error {
gui.State.Diff = DiffState{}
gui.State.Modes.Diffing = Diffing{}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
}
@ -20,7 +20,7 @@ func (gui *Gui) renderDiff() error {
filterArg := ""
if gui.inFilterMode() {
filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath)
filterArg = fmt.Sprintf(" -- %s", gui.State.Modes.Filtering.Path)
}
cmd := gui.OSCommand.ExecutableFromString(
@ -42,54 +42,33 @@ func (gui *Gui) renderDiff() error {
// flicking through branches it will be using the local branch name.
func (gui *Gui) currentDiffTerminals() []string {
switch gui.currentContextKey() {
case FILES_CONTEXT_KEY:
// not supporting files for now
case COMMIT_FILES_CONTEXT_KEY:
// not supporting commit files for now
case BRANCH_COMMITS_CONTEXT_KEY:
item := gui.getSelectedLocalCommit()
if item != nil {
return []string{item.RefName()}
}
case REFLOG_COMMITS_CONTEXT_KEY:
item := gui.getSelectedReflogCommit()
if item != nil {
return []string{item.RefName()}
}
case STASH_CONTEXT_KEY:
item := gui.getSelectedStashEntry()
if item != nil {
return []string{item.RefName()}
}
case "":
return nil
case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
// not supporting these for now because I'm not sure how it would actually work
return nil
case LOCAL_BRANCHES_CONTEXT_KEY:
// for our local branches we want to include both the branch and its upstream
branch := gui.getSelectedBranch()
if branch != nil {
names := []string{branch.RefName()}
names := []string{branch.ID()}
if branch.UpstreamName != "" {
names = append(names, branch.UpstreamName)
}
return names
}
return nil
case REMOTES_CONTEXT_KEY:
item := gui.getSelectedRemote()
if item != nil {
return []string{item.RefName()}
default:
context := gui.currentSideContext()
if context == nil {
return nil
}
case REMOTE_BRANCHES_CONTEXT_KEY:
item := gui.getSelectedRemoteBranch()
if item != nil {
return []string{item.RefName()}
}
case TAGS_CONTEXT_KEY:
item := gui.getSelectedTag()
if item != nil {
return []string{item.RefName()}
item := context.GetSelectedItem()
if item == nil {
return nil
}
return []string{item.ID()}
}
return nil
}
func (gui *Gui) currentDiffTerminal() string {
@ -101,13 +80,13 @@ func (gui *Gui) currentDiffTerminal() string {
}
func (gui *Gui) diffStr() string {
output := gui.State.Diff.Ref
output := gui.State.Modes.Diffing.Ref
right := gui.currentDiffTerminal()
if right != "" {
output += " " + right
}
if gui.State.Diff.Reverse {
if gui.State.Modes.Diffing.Reverse {
output += " -R"
}
return output
@ -127,7 +106,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error
{
displayString: fmt.Sprintf("%s %s", gui.Tr.SLocalize("diff"), name),
onPress: func() error {
gui.State.Diff.Ref = name
gui.State.Modes.Diffing.Ref = name
// can scope this down based on current view but too lazy right now
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
@ -140,7 +119,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error
displayString: gui.Tr.SLocalize("enterRefToDiff"),
onPress: func() error {
return gui.prompt(v, gui.Tr.SLocalize("enteRefName"), "", func(response string) error {
gui.State.Diff.Ref = strings.TrimSpace(response)
gui.State.Modes.Diffing.Ref = strings.TrimSpace(response)
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
})
},
@ -152,14 +131,14 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error
{
displayString: gui.Tr.SLocalize("swapDiff"),
onPress: func() error {
gui.State.Diff.Reverse = !gui.State.Diff.Reverse
gui.State.Modes.Diffing.Reverse = !gui.State.Modes.Diffing.Reverse
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
},
{
displayString: gui.Tr.SLocalize("exitDiffMode"),
onPress: func() error {
gui.State.Diff = DiffState{}
gui.State.Modes.Diffing = Diffing{}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
},

View File

@ -1,7 +1,7 @@
package gui
func (gui *Gui) inFilterMode() bool {
return gui.State.FilterPath != ""
return gui.State.Modes.Filtering.Path != ""
}
func (gui *Gui) validateNotInFilterMode() (bool, error) {
@ -22,6 +22,6 @@ func (gui *Gui) validateNotInFilterMode() (bool, error) {
}
func (gui *Gui) exitFilterMode() error {
gui.State.FilterPath = ""
gui.State.Modes.Filtering.Path = ""
return gui.Errors.ErrRestart
}

View File

@ -32,7 +32,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro
menuItems = append(menuItems, &menuItem{
displayString: fmt.Sprintf("%s '%s'", gui.Tr.SLocalize("filterBy"), fileName),
onPress: func() error {
gui.State.FilterPath = fileName
gui.State.Modes.Filtering.Path = fileName
return gui.Errors.ErrRestart
},
})
@ -42,7 +42,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro
displayString: gui.Tr.SLocalize("filterPathOption"),
onPress: func() error {
return gui.prompt(v, gui.Tr.SLocalize("enterFileName"), "", func(response string) error {
gui.State.FilterPath = strings.TrimSpace(response)
gui.State.Modes.Filtering.Path = strings.TrimSpace(response)
return gui.Errors.ErrRestart
})
},
@ -52,7 +52,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro
menuItems = append(menuItems, &menuItem{
displayString: gui.Tr.SLocalize("exitFilterMode"),
onPress: func() error {
gui.State.FilterPath = ""
gui.State.Modes.Filtering.Path = ""
return gui.Errors.ErrRestart
},
})

View File

@ -227,11 +227,25 @@ const (
)
// if ref is blank we're not diffing anything
type DiffState struct {
type Diffing struct {
Ref string
Reverse bool
}
type Filtering struct {
Path string // the filename that gets passed to git log
}
type CherryPicking struct {
CherryPickedCommits []*commands.Commit
}
type Modes struct {
Filtering Filtering
CherryPicking CherryPicking
Diffing Diffing
}
type guiState struct {
Files []*commands.File
Branches []*commands.Branch
@ -253,7 +267,6 @@ type guiState struct {
Updating bool
Panels *panelStates
MainContext string // used to keep the main and secondary views' contexts in sync
CherryPickedCommits []*commands.Commit
SplitMainPanel bool
RetainOriginalDir bool
IsRefreshingFiles bool
@ -266,9 +279,9 @@ type guiState struct {
PrevMainWidth int
PrevMainHeight int
OldInformation string
StartupStage int // one of INITIAL and COMPLETE. Allows us to not load everything at once
FilterPath string // the filename that gets passed to git log
Diff DiffState
StartupStage int // one of INITIAL and COMPLETE. Allows us to not load everything at once
Modes Modes
ContextStack []Context
ViewContextMap map[string]Context
@ -284,10 +297,20 @@ type guiState struct {
func (gui *Gui) resetState() {
// we carry over the filter path and diff state
prevFilterPath := ""
prevDiff := DiffState{}
prevDiff := Diffing{}
if gui.State != nil {
prevFilterPath = gui.State.FilterPath
prevDiff = gui.State.Diff
prevFilterPath = gui.State.Modes.Filtering.Path
prevDiff = gui.State.Modes.Diffing
}
modes := Modes{
Filtering: Filtering{
Path: prevFilterPath,
},
CherryPicking: CherryPicking{
CherryPickedCommits: make([]*commands.Commit, 0),
},
Diffing: prevDiff,
}
gui.State = &guiState{
@ -295,7 +318,6 @@ func (gui *Gui) resetState() {
Commits: make([]*commands.Commit, 0),
FilteredReflogCommits: make([]*commands.Commit, 0),
ReflogCommits: make([]*commands.Commit, 0),
CherryPickedCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0),
Panels: &panelStates{
// TODO: work out why some of these are -1 and some are 0. Last time I checked there was a good reason but I'm less certain now
@ -319,8 +341,7 @@ func (gui *Gui) resetState() {
},
SideView: nil,
Ptmx: nil,
FilterPath: prevFilterPath,
Diff: prevDiff,
Modes: modes,
ViewContextMap: gui.initialViewContextMap(),
}
}
@ -341,7 +362,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
}
gui.resetState()
gui.State.FilterPath = filterPath
gui.State.Modes.Filtering.Path = filterPath
gui.Contexts = gui.contextTree()
gui.ViewTabContextMap = gui.viewTabContextMap()

View File

@ -758,7 +758,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "commits",
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
Key: gui.getKey("commits.cherryPickCopy"),
Handler: gui.handleCopyCommit,
Handler: gui.wrappedHandler(gui.handleCopyCommit),
Description: gui.Tr.SLocalize("cherryPickCopy"),
},
{
@ -772,14 +772,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "commits",
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
Key: gui.getKey("commits.cherryPickCopyRange"),
Handler: gui.handleCopyCommitRange,
Handler: gui.wrappedHandler(gui.handleCopyCommitRange),
Description: gui.Tr.SLocalize("cherryPickCopyRange"),
},
{
ViewName: "commits",
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
Key: gui.getKey("commits.pasteCommits"),
Handler: gui.HandlePasteCommits,
Handler: gui.wrappedHandler(gui.HandlePasteCommits),
Description: gui.Tr.SLocalize("pasteCommits"),
},
{
@ -867,6 +867,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.wrappedHandler(gui.handleNewBranchOffCurrentItem),
Description: gui.Tr.SLocalize("newBranch"),
},
{
ViewName: "commits",
Contexts: []string{SUB_COMMITS_CONTEXT_KEY},
Key: gui.getKey("commits.cherryPickCopy"),
Handler: gui.wrappedHandler(gui.handleCopyCommit),
Description: gui.Tr.SLocalize("cherryPickCopy"),
},
{
ViewName: "stash",
Key: gui.getKey("universal.goInto"),

View File

@ -16,11 +16,11 @@ func (gui *Gui) informationStr() string {
if gui.inDiffMode() {
return utils.ColoredString(fmt.Sprintf("%s %s %s", gui.Tr.SLocalize("showingGitDiff"), "git diff "+gui.diffStr(), utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgMagenta)
} else if gui.inFilterMode() {
return utils.ColoredString(fmt.Sprintf("%s '%s' %s", gui.Tr.SLocalize("filteringBy"), gui.State.FilterPath, utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgRed, color.Bold)
return utils.ColoredString(fmt.Sprintf("%s '%s' %s", gui.Tr.SLocalize("filteringBy"), gui.State.Modes.Filtering.Path, utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgRed, color.Bold)
} else if gui.GitCommand.PatchManager.Active() {
return utils.ColoredString(fmt.Sprintf("%s %s", gui.Tr.SLocalize("buildingPatch"), utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgYellow, color.Bold)
} else if len(gui.State.CherryPickedCommits) > 0 {
return utils.ColoredString(fmt.Sprintf("%d commits copied", len(gui.State.CherryPickedCommits)), color.FgCyan)
} else if len(gui.State.Modes.CherryPicking.CherryPickedCommits) > 0 {
return utils.ColoredString(fmt.Sprintf("%d commits copied", len(gui.State.Modes.CherryPicking.CherryPickedCommits)), color.FgCyan)
} else if gui.g.Mouse {
donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.SLocalize("Donate"))
return donate + " " + gui.Config.GetVersion()

View File

@ -275,7 +275,7 @@ func (gui *Gui) filesListContext() *ListContext {
RendersToMainView: false,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
return presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_NOTHING,
SelectedItem: func() ListItem { return gui.getSelectedFile() },
@ -293,7 +293,7 @@ func (gui *Gui) branchesListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_COMMITS,
SelectedItem: func() ListItem { return gui.getSelectedBranch() },
@ -312,7 +312,7 @@ func (gui *Gui) remotesListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Diff.Ref)
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_BRANCHES,
SelectedItem: func() ListItem { return gui.getSelectedRemote() },
@ -330,7 +330,7 @@ func (gui *Gui) remoteBranchesListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Diff.Ref)
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_COMMITS,
SelectedItem: func() ListItem { return gui.getSelectedRemoteBranch() },
@ -348,7 +348,7 @@ func (gui *Gui) tagsListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref)
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_COMMITS,
SelectedItem: func() ListItem { return gui.getSelectedTag() },
@ -367,7 +367,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.CherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_FILES,
SelectedItem: func() ListItem { return gui.getSelectedLocalCommit() },
@ -385,7 +385,7 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_FILES,
SelectedItem: func() ListItem { return gui.getSelectedReflogCommit() },
@ -403,7 +403,7 @@ func (gui *Gui) subCommitsListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
return presentation.GetCommitListDisplayStrings(gui.State.SubCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.CherryPickedCommitShaMap(), gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_COMMITS,
SelectedItem: func() ListItem { return gui.getSelectedSubCommit() },
@ -421,7 +421,7 @@ func (gui *Gui) stashListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Diff.Ref)
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_FILES,
SelectedItem: func() ListItem { return gui.getSelectedStashEntry() },
@ -440,7 +440,7 @@ func (gui *Gui) commitFilesListContext() *ListContext {
RendersToMainView: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
return presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Modes.Diffing.Ref)
},
Contains: CONTAINS_NOTHING,
SelectedItem: func() ListItem { return gui.getSelectedCommitFile() },

View File

@ -31,7 +31,7 @@ func (gui *Gui) handleCreateRecentReposMenu() error {
return err
}
gui.GitCommand = newGitCommand
gui.State.FilterPath = ""
gui.State.Modes.Filtering.Path = ""
return gui.Errors.ErrSwitchRepo
},
}

View File

@ -24,7 +24,7 @@ func (gui *Gui) handleReflogCommitSelect() error {
task = gui.createRenderStringTask("No reflog history")
} else {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.FilterPath),
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path),
)
task = gui.createRunPtyTask(cmd)
@ -73,7 +73,7 @@ func (gui *Gui) refreshReflogCommits() error {
}
if gui.inFilterMode() {
if err := refresh(&state.FilteredReflogCommits, state.FilterPath); err != nil {
if err := refresh(&state.FilteredReflogCommits, state.Modes.Filtering.Path); err != nil {
return err
}
} else {

View File

@ -37,7 +37,7 @@ func (gui *Gui) handleStashEntrySelect() error {
}
func (gui *Gui) refreshStashEntries() error {
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.FilterPath)
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.Modes.Filtering.Path)
return gui.Contexts.Stash.Context.HandleRender()
}

View File

@ -24,7 +24,7 @@ func (gui *Gui) handleSubCommitSelect() error {
task = gui.createRenderStringTask("No commits")
} else {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.FilterPath),
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path),
)
task = gui.createRunPtyTask(cmd)
@ -79,12 +79,12 @@ func (gui *Gui) handleViewSubCommitFiles() error {
func (gui *Gui) switchToSubCommitsContext(refName string) error {
// need to populate my sub commits
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits)
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.Modes.CherryPicking.CherryPickedCommits)
commits, err := builder.GetCommits(
commands.GetCommitsOptions{
Limit: gui.State.Panels.Commits.LimitCommits,
FilterPath: gui.State.FilterPath,
FilterPath: gui.State.Modes.Filtering.Path,
IncludeRebaseCommits: false,
RefName: refName,
},