mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-19 00:28:03 +02:00
fix some things
This commit is contained in:
@ -145,7 +145,7 @@ func (gui *Gui) contextTree() context.ContextTree {
|
||||
},
|
||||
Merging: &BasicContext{
|
||||
OnFocus: OnFocusWrapper(func() error { return gui.renderConflictsWithLock(true) }),
|
||||
Kind: MAIN_CONTEXT,
|
||||
Kind: types.MAIN_CONTEXT,
|
||||
ViewName: "main",
|
||||
Key: MAIN_MERGING_CONTEXT_KEY,
|
||||
OnGetOptionsMap: gui.getMergingOptions,
|
||||
|
@ -4,15 +4,16 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCanDeactivatePopupContextsWithoutViews(t *testing.T) {
|
||||
contexts := []func(gui *Gui) Context{
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Credentials },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Confirmation },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.CommitMessage },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Search },
|
||||
contexts := []func(gui *Gui) types.Context{
|
||||
func(gui *Gui) types.Context { return gui.State.Contexts.Credentials },
|
||||
func(gui *Gui) types.Context { return gui.State.Contexts.Confirmation },
|
||||
func(gui *Gui) types.Context { return gui.State.Contexts.CommitMessage },
|
||||
func(gui *Gui) types.Context { return gui.State.Contexts.Search },
|
||||
}
|
||||
|
||||
for _, c := range contexts {
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
)
|
||||
|
||||
type BisectController struct {
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
git *commands.GitCommand
|
||||
c *ControllerCommon
|
||||
getContext func() types.IListContext
|
||||
git *commands.GitCommand
|
||||
|
||||
getSelectedLocalCommit func() *models.Commit
|
||||
getCommits func() []*models.Commit
|
||||
@ -25,16 +25,16 @@ var _ types.IController = &BisectController{}
|
||||
|
||||
func NewBisectController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getContext func() types.IListContext,
|
||||
git *commands.GitCommand,
|
||||
|
||||
getSelectedLocalCommit func() *models.Commit,
|
||||
getCommits func() []*models.Commit,
|
||||
) *BisectController {
|
||||
return &BisectController{
|
||||
c: c,
|
||||
context: context,
|
||||
git: git,
|
||||
c: c,
|
||||
getContext: getContext,
|
||||
git: git,
|
||||
|
||||
getSelectedLocalCommit: getSelectedLocalCommit,
|
||||
getCommits: getCommits,
|
||||
@ -249,8 +249,8 @@ func (self *BisectController) selectCurrentBisectCommit() {
|
||||
// find index of commit with that sha, move cursor to that.
|
||||
for i, commit := range self.getCommits() {
|
||||
if commit.Sha == info.GetCurrentSha() {
|
||||
self.context.GetPanelState().SetSelectedLineIdx(i)
|
||||
_ = self.context.HandleFocus()
|
||||
self.getContext().GetPanelState().SetSelectedLineIdx(i)
|
||||
_ = self.getContext().HandleFocus()
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -269,5 +269,5 @@ func (self *BisectController) checkSelected(callback func(*models.Commit) error)
|
||||
}
|
||||
|
||||
func (self *BisectController) Context() types.Context {
|
||||
return self.context
|
||||
return self.getContext()
|
||||
}
|
||||
|
@ -22,14 +22,14 @@ type FilesController struct {
|
||||
// case I would actually prefer a _zero_ letter variable name in the form of
|
||||
// struct embedding, but Go does not allow hiding public fields in an embedded struct
|
||||
// to the client
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
git *commands.GitCommand
|
||||
os *oscommands.OSCommand
|
||||
c *ControllerCommon
|
||||
getContext func() types.IListContext
|
||||
git *commands.GitCommand
|
||||
os *oscommands.OSCommand
|
||||
|
||||
getSelectedFileNode func() *filetree.FileNode
|
||||
allContexts context.ContextTree
|
||||
fileTreeViewModel *filetree.FileTreeViewModel
|
||||
getContexts func() context.ContextTree
|
||||
getViewModel func() *filetree.FileTreeViewModel
|
||||
enterSubmodule func(submodule *models.SubmoduleConfig) error
|
||||
getSubmodules func() []*models.SubmoduleConfig
|
||||
setCommitMessage func(message string)
|
||||
@ -49,12 +49,12 @@ var _ types.IController = &FilesController{}
|
||||
|
||||
func NewFilesController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getContext func() types.IListContext,
|
||||
git *commands.GitCommand,
|
||||
os *oscommands.OSCommand,
|
||||
getSelectedFileNode func() *filetree.FileNode,
|
||||
allContexts context.ContextTree,
|
||||
fileTreeViewModel *filetree.FileTreeViewModel,
|
||||
allContexts func() context.ContextTree,
|
||||
getViewModel func() *filetree.FileTreeViewModel,
|
||||
enterSubmodule func(submodule *models.SubmoduleConfig) error,
|
||||
getSubmodules func() []*models.SubmoduleConfig,
|
||||
setCommitMessage func(message string),
|
||||
@ -70,12 +70,12 @@ func NewFilesController(
|
||||
) *FilesController {
|
||||
return &FilesController{
|
||||
c: c,
|
||||
context: context,
|
||||
getContext: getContext,
|
||||
git: git,
|
||||
os: os,
|
||||
getSelectedFileNode: getSelectedFileNode,
|
||||
allContexts: allContexts,
|
||||
fileTreeViewModel: fileTreeViewModel,
|
||||
getContexts: allContexts,
|
||||
getViewModel: getViewModel,
|
||||
enterSubmodule: enterSubmodule,
|
||||
getSubmodules: getSubmodules,
|
||||
setCommitMessage: setCommitMessage,
|
||||
@ -100,7 +100,7 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co
|
||||
},
|
||||
{
|
||||
Key: gocui.MouseLeft,
|
||||
Handler: func() error { return self.context.HandleClick(self.checkSelectedFileNode(self.press)) },
|
||||
Handler: func() error { return self.getContext().HandleClick(self.checkSelectedFileNode(self.press)) },
|
||||
},
|
||||
{
|
||||
Key: getKey("<c-b>"), // TODO: softcode
|
||||
@ -129,7 +129,7 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Universal.Edit),
|
||||
Handler: self.edit,
|
||||
Handler: self.checkSelectedFileNode(self.edit),
|
||||
Description: self.c.Tr.LcEditFile,
|
||||
},
|
||||
{
|
||||
@ -139,7 +139,7 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Files.IgnoreFile),
|
||||
Handler: self.ignore,
|
||||
Handler: self.checkSelectedFileNode(self.ignore),
|
||||
Description: self.c.Tr.LcIgnoreFile,
|
||||
},
|
||||
{
|
||||
@ -192,7 +192,7 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return append(bindings, self.getContext().Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *FilesController) press(node *filetree.FileNode) error {
|
||||
@ -200,7 +200,7 @@ func (self *FilesController) press(node *filetree.FileNode) error {
|
||||
file := node.File
|
||||
|
||||
if file.HasInlineMergeConflicts {
|
||||
return self.c.PushContext(self.allContexts.Merging)
|
||||
return self.c.PushContext(self.getContexts().Merging)
|
||||
}
|
||||
|
||||
if file.HasUnstagedChanges {
|
||||
@ -239,7 +239,7 @@ func (self *FilesController) press(node *filetree.FileNode) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.context.HandleFocus()
|
||||
return self.getContext().HandleFocus()
|
||||
}
|
||||
|
||||
func (self *FilesController) checkSelectedFileNode(callback func(*filetree.FileNode) error) func() error {
|
||||
@ -253,19 +253,8 @@ func (self *FilesController) checkSelectedFileNode(callback func(*filetree.FileN
|
||||
}
|
||||
}
|
||||
|
||||
func (self *FilesController) checkSelectedFile(callback func(*models.File) error) func() error {
|
||||
return func() error {
|
||||
file := self.getSelectedFile()
|
||||
if file == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return callback(file)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *FilesController) Context() types.Context {
|
||||
return self.context
|
||||
return self.getContext()
|
||||
}
|
||||
|
||||
func (self *FilesController) getSelectedFile() *models.File {
|
||||
@ -305,11 +294,11 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error {
|
||||
return self.c.ErrorMsg(self.c.Tr.FileStagingRequirements)
|
||||
}
|
||||
|
||||
return self.c.PushContext(self.allContexts.Staging, opts)
|
||||
return self.c.PushContext(self.getContexts().Staging, opts)
|
||||
}
|
||||
|
||||
func (self *FilesController) allFilesStaged() bool {
|
||||
for _, file := range self.fileTreeViewModel.GetAllFiles() {
|
||||
for _, file := range self.getViewModel().GetAllFiles() {
|
||||
if file.HasUnstagedChanges {
|
||||
return false
|
||||
}
|
||||
@ -334,15 +323,10 @@ func (self *FilesController) stageAll() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.allContexts.Files.HandleFocus()
|
||||
return self.getContexts().Files.HandleFocus()
|
||||
}
|
||||
|
||||
func (self *FilesController) ignore() error {
|
||||
node := self.getSelectedFileNode()
|
||||
if node == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *FilesController) ignore(node *filetree.FileNode) error {
|
||||
if node.GetPath() == ".gitignore" {
|
||||
return self.c.ErrorMsg("Cannot ignore .gitignore")
|
||||
}
|
||||
@ -444,7 +428,7 @@ func (self *FilesController) HandleCommitPress() error {
|
||||
return self.c.Error(err)
|
||||
}
|
||||
|
||||
if self.fileTreeViewModel.GetItemsLength() == 0 {
|
||||
if self.getViewModel().GetItemsLength() == 0 {
|
||||
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
||||
}
|
||||
|
||||
@ -469,7 +453,7 @@ func (self *FilesController) HandleCommitPress() error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := self.c.PushContext(self.allContexts.CommitMessage); err != nil {
|
||||
if err := self.c.PushContext(self.getContexts().CommitMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -495,7 +479,7 @@ func (self *FilesController) promptToStageAllAndRetry(retry func() error) error
|
||||
}
|
||||
|
||||
func (self *FilesController) handleAmendCommitPress() error {
|
||||
if self.fileTreeViewModel.GetItemsLength() == 0 {
|
||||
if self.getViewModel().GetItemsLength() == 0 {
|
||||
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
||||
}
|
||||
|
||||
@ -521,7 +505,7 @@ func (self *FilesController) handleAmendCommitPress() error {
|
||||
// HandleCommitEditorPress - handle when the user wants to commit changes via
|
||||
// their editor rather than via the popup panel
|
||||
func (self *FilesController) HandleCommitEditorPress() error {
|
||||
if self.fileTreeViewModel.GetItemsLength() == 0 {
|
||||
if self.getViewModel().GetItemsLength() == 0 {
|
||||
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
||||
}
|
||||
|
||||
@ -562,16 +546,11 @@ func (self *FilesController) handleStatusFilterPressed() error {
|
||||
}
|
||||
|
||||
func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayFilter) error {
|
||||
self.fileTreeViewModel.SetFilter(filter)
|
||||
return self.c.PostRefreshUpdate(self.context)
|
||||
self.getViewModel().SetFilter(filter)
|
||||
return self.c.PostRefreshUpdate(self.getContext())
|
||||
}
|
||||
|
||||
func (self *FilesController) edit() error {
|
||||
node := self.getSelectedFileNode()
|
||||
if node == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *FilesController) edit(node *filetree.FileNode) error {
|
||||
if node.File == nil {
|
||||
return self.c.ErrorMsg(self.c.Tr.ErrCannotEditDirectory)
|
||||
}
|
||||
@ -594,7 +573,7 @@ func (self *FilesController) switchToMerge() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.switchToMergeFn(path)
|
||||
return self.switchToMergeFn(file.Name)
|
||||
}
|
||||
|
||||
func (self *FilesController) handleCustomCommand() error {
|
||||
@ -658,9 +637,9 @@ func (self *FilesController) handleToggleDirCollapsed() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.fileTreeViewModel.ToggleCollapsed(node.GetPath())
|
||||
self.getViewModel().ToggleCollapsed(node.GetPath())
|
||||
|
||||
if err := self.c.PostRefreshUpdate(self.allContexts.Files); err != nil {
|
||||
if err := self.c.PostRefreshUpdate(self.getContexts().Files); err != nil {
|
||||
self.c.Log.Error(err)
|
||||
}
|
||||
|
||||
@ -671,18 +650,18 @@ func (self *FilesController) toggleTreeView() error {
|
||||
// get path of currently selected file
|
||||
path := self.getSelectedPath()
|
||||
|
||||
self.fileTreeViewModel.ToggleShowTree()
|
||||
self.getViewModel().ToggleShowTree()
|
||||
|
||||
// find that same node in the new format and move the cursor to it
|
||||
if path != "" {
|
||||
self.fileTreeViewModel.ExpandToPath(path)
|
||||
index, found := self.fileTreeViewModel.GetIndexForPath(path)
|
||||
self.getViewModel().ExpandToPath(path)
|
||||
index, found := self.getViewModel().GetIndexForPath(path)
|
||||
if found {
|
||||
self.context.GetPanelState().SetSelectedLineIdx(index)
|
||||
self.getContext().GetPanelState().SetSelectedLineIdx(index)
|
||||
}
|
||||
}
|
||||
|
||||
return self.c.PostRefreshUpdate(self.context)
|
||||
return self.c.PostRefreshUpdate(self.getContext())
|
||||
}
|
||||
|
||||
func (self *FilesController) OpenMergeTool() error {
|
||||
|
@ -26,11 +26,11 @@ type (
|
||||
)
|
||||
|
||||
type LocalCommitsController struct {
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
os *oscommands.OSCommand
|
||||
git *commands.GitCommand
|
||||
refHelper IRefHelper
|
||||
c *ControllerCommon
|
||||
getContext func() types.IListContext
|
||||
os *oscommands.OSCommand
|
||||
git *commands.GitCommand
|
||||
refHelper IRefHelper
|
||||
|
||||
getSelectedLocalCommit func() *models.Commit
|
||||
getCommits func() []*models.Commit
|
||||
@ -51,7 +51,7 @@ var _ types.IController = &LocalCommitsController{}
|
||||
|
||||
func NewLocalCommitsController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getContext func() types.IListContext,
|
||||
os *oscommands.OSCommand,
|
||||
git *commands.GitCommand,
|
||||
refHelper IRefHelper,
|
||||
@ -71,7 +71,7 @@ func NewLocalCommitsController(
|
||||
) *LocalCommitsController {
|
||||
return &LocalCommitsController{
|
||||
c: c,
|
||||
context: context,
|
||||
getContext: getContext,
|
||||
os: os,
|
||||
git: git,
|
||||
refHelper: refHelper,
|
||||
@ -178,7 +178,7 @@ func (self *LocalCommitsController) Keybindings(
|
||||
},
|
||||
{
|
||||
Key: gocui.MouseLeft,
|
||||
Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) },
|
||||
Handler: func() error { return self.getContext().HandleClick(self.checkSelected(self.enter)) },
|
||||
},
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ func (self *LocalCommitsController) Keybindings(
|
||||
},
|
||||
}...)
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return append(bindings, self.getContext().Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) squashDown() error {
|
||||
@ -420,7 +420,7 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action string) (bool,
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) handleCommitMoveDown() error {
|
||||
index := self.context.GetPanelState().GetSelectedLineIdx()
|
||||
index := self.getContext().GetPanelState().GetSelectedLineIdx()
|
||||
commits := self.getCommits()
|
||||
selectedCommit := self.getCommits()[index]
|
||||
if selectedCommit.Status == "rebasing" {
|
||||
@ -436,7 +436,7 @@ func (self *LocalCommitsController) handleCommitMoveDown() error {
|
||||
if err := self.git.Rebase.MoveTodoDown(index); err != nil {
|
||||
return self.c.Error(err)
|
||||
}
|
||||
self.context.HandleNextLine()
|
||||
_ = self.getContext().HandleNextLine()
|
||||
return self.c.Refresh(types.RefreshOptions{
|
||||
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
|
||||
})
|
||||
@ -446,14 +446,14 @@ func (self *LocalCommitsController) handleCommitMoveDown() error {
|
||||
self.c.LogAction(self.c.Tr.Actions.MoveCommitDown)
|
||||
err := self.git.Rebase.MoveCommitDown(self.getCommits(), index)
|
||||
if err == nil {
|
||||
self.context.HandleNextLine()
|
||||
_ = self.getContext().HandleNextLine()
|
||||
}
|
||||
return self.checkMergeOrRebase(err)
|
||||
})
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) handleCommitMoveUp() error {
|
||||
index := self.context.GetPanelState().GetSelectedLineIdx()
|
||||
index := self.getContext().GetPanelState().GetSelectedLineIdx()
|
||||
if index == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -471,7 +471,7 @@ func (self *LocalCommitsController) handleCommitMoveUp() error {
|
||||
if err := self.git.Rebase.MoveTodoDown(index - 1); err != nil {
|
||||
return self.c.Error(err)
|
||||
}
|
||||
self.context.HandlePrevLine()
|
||||
_ = self.getContext().HandlePrevLine()
|
||||
return self.c.Refresh(types.RefreshOptions{
|
||||
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
|
||||
})
|
||||
@ -481,7 +481,7 @@ func (self *LocalCommitsController) handleCommitMoveUp() error {
|
||||
self.c.LogAction(self.c.Tr.Actions.MoveCommitUp)
|
||||
err := self.git.Rebase.MoveCommitDown(self.getCommits(), index-1)
|
||||
if err == nil {
|
||||
self.context.HandlePrevLine()
|
||||
_ = self.getContext().HandlePrevLine()
|
||||
}
|
||||
return self.checkMergeOrRebase(err)
|
||||
})
|
||||
@ -549,7 +549,7 @@ func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.C
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) afterRevertCommit() error {
|
||||
self.context.HandleNextLine()
|
||||
_ = self.getContext().HandleNextLine()
|
||||
return self.c.Refresh(types.RefreshOptions{
|
||||
Mode: types.BLOCK_UI, Scope: []types.RefreshableView{types.COMMITS, types.BRANCHES},
|
||||
})
|
||||
@ -559,7 +559,7 @@ func (self *LocalCommitsController) enter(commit *models.Commit) error {
|
||||
return self.switchToCommitFilesContext(SwitchToCommitFilesContextOpts{
|
||||
RefName: commit.Sha,
|
||||
CanRebase: true,
|
||||
Context: self.context,
|
||||
Context: self.getContext(),
|
||||
WindowName: "commits",
|
||||
})
|
||||
}
|
||||
@ -647,7 +647,7 @@ func (self *LocalCommitsController) gotoBottom() error {
|
||||
}
|
||||
}
|
||||
|
||||
self.context.HandleGotoBottom()
|
||||
_ = self.getContext().HandleGotoBottom()
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -779,5 +779,5 @@ func (self *LocalCommitsController) checkSelected(callback func(*models.Commit)
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) Context() types.Context {
|
||||
return self.context
|
||||
return self.getContext()
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
type MenuController struct {
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
c *ControllerCommon
|
||||
getContext func() types.IListContext
|
||||
|
||||
getSelectedMenuItem func() *popup.MenuItem
|
||||
}
|
||||
@ -18,12 +18,12 @@ var _ types.IController = &MenuController{}
|
||||
|
||||
func NewMenuController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getContext func() types.IListContext,
|
||||
getSelectedMenuItem func() *popup.MenuItem,
|
||||
) *MenuController {
|
||||
return &MenuController{
|
||||
c: c,
|
||||
context: context,
|
||||
getContext: getContext,
|
||||
getSelectedMenuItem: getSelectedMenuItem,
|
||||
}
|
||||
}
|
||||
@ -44,11 +44,11 @@ func (self *MenuController) Keybindings(getKey func(key string) interface{}, con
|
||||
},
|
||||
{
|
||||
Key: gocui.MouseLeft,
|
||||
Handler: func() error { return self.context.HandleClick(self.press) },
|
||||
Handler: func() error { return self.getContext().HandleClick(self.press) },
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return append(bindings, self.getContext().Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *MenuController) press() error {
|
||||
@ -66,5 +66,5 @@ func (self *MenuController) press() error {
|
||||
}
|
||||
|
||||
func (self *MenuController) Context() types.Context {
|
||||
return self.context
|
||||
return self.getContext()
|
||||
}
|
||||
|
@ -14,13 +14,13 @@ import (
|
||||
)
|
||||
|
||||
type RemotesController struct {
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
git *commands.GitCommand
|
||||
c *ControllerCommon
|
||||
getContext func() types.IListContext
|
||||
git *commands.GitCommand
|
||||
|
||||
getSelectedRemote func() *models.Remote
|
||||
setRemoteBranches func([]*models.RemoteBranch)
|
||||
allContexts context.ContextTree
|
||||
getContexts func() context.ContextTree
|
||||
fetchMutex *sync.Mutex
|
||||
}
|
||||
|
||||
@ -28,9 +28,9 @@ var _ types.IController = &RemotesController{}
|
||||
|
||||
func NewRemotesController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getContext func() types.IListContext,
|
||||
git *commands.GitCommand,
|
||||
allContexts context.ContextTree,
|
||||
getContexts func() context.ContextTree,
|
||||
getSelectedRemote func() *models.Remote,
|
||||
setRemoteBranches func([]*models.RemoteBranch),
|
||||
fetchMutex *sync.Mutex,
|
||||
@ -38,8 +38,8 @@ func NewRemotesController(
|
||||
return &RemotesController{
|
||||
c: c,
|
||||
git: git,
|
||||
allContexts: allContexts,
|
||||
context: context,
|
||||
getContexts: getContexts,
|
||||
getContext: getContext,
|
||||
getSelectedRemote: getSelectedRemote,
|
||||
setRemoteBranches: setRemoteBranches,
|
||||
fetchMutex: fetchMutex,
|
||||
@ -54,7 +54,7 @@ func (self *RemotesController) Keybindings(getKey func(key string) interface{},
|
||||
},
|
||||
{
|
||||
Key: gocui.MouseLeft,
|
||||
Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) },
|
||||
Handler: func() error { return self.getContext().HandleClick(self.checkSelected(self.enter)) },
|
||||
},
|
||||
{
|
||||
Key: getKey(config.Branches.FetchRemote),
|
||||
@ -78,7 +78,7 @@ func (self *RemotesController) Keybindings(getKey func(key string) interface{},
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return append(bindings, self.getContext().Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *RemotesController) enter(remote *models.Remote) error {
|
||||
@ -89,9 +89,9 @@ func (self *RemotesController) enter(remote *models.Remote) error {
|
||||
if len(remote.Branches) == 0 {
|
||||
newSelectedLine = -1
|
||||
}
|
||||
self.allContexts.RemoteBranches.GetPanelState().SetSelectedLineIdx(newSelectedLine)
|
||||
self.getContexts().RemoteBranches.GetPanelState().SetSelectedLineIdx(newSelectedLine)
|
||||
|
||||
return self.c.PushContext(self.allContexts.RemoteBranches)
|
||||
return self.c.PushContext(self.getContexts().RemoteBranches)
|
||||
}
|
||||
|
||||
func (self *RemotesController) add() error {
|
||||
@ -200,5 +200,5 @@ func (self *RemotesController) checkSelected(callback func(*models.Remote) error
|
||||
}
|
||||
|
||||
func (self *RemotesController) Context() types.Context {
|
||||
return self.context
|
||||
return self.getContext()
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
|
||||
type TagsController struct {
|
||||
c *ControllerCommon
|
||||
context types.IListContext
|
||||
getContext func() types.IListContext
|
||||
git *commands.GitCommand
|
||||
allContexts context.ContextTree
|
||||
getContexts func() context.ContextTree
|
||||
|
||||
refHelper IRefHelper
|
||||
suggestionsHelper ISuggestionsHelper
|
||||
@ -27,9 +27,9 @@ var _ types.IController = &TagsController{}
|
||||
|
||||
func NewTagsController(
|
||||
c *ControllerCommon,
|
||||
context types.IListContext,
|
||||
getContext func() types.IListContext,
|
||||
git *commands.GitCommand,
|
||||
allContexts context.ContextTree,
|
||||
getContexts func() context.ContextTree,
|
||||
refHelper IRefHelper,
|
||||
suggestionsHelper ISuggestionsHelper,
|
||||
|
||||
@ -38,9 +38,9 @@ func NewTagsController(
|
||||
) *TagsController {
|
||||
return &TagsController{
|
||||
c: c,
|
||||
context: context,
|
||||
getContext: getContext,
|
||||
git: git,
|
||||
allContexts: allContexts,
|
||||
getContexts: getContexts,
|
||||
refHelper: refHelper,
|
||||
suggestionsHelper: suggestionsHelper,
|
||||
|
||||
@ -84,7 +84,7 @@ func (self *TagsController) Keybindings(getKey func(key string) interface{}, con
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
return append(bindings, self.getContext().Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *TagsController) checkout(tag *models.Tag) error {
|
||||
@ -92,7 +92,7 @@ func (self *TagsController) checkout(tag *models.Tag) error {
|
||||
if err := self.refHelper.CheckoutRef(tag.Name, types.CheckoutRefOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return self.c.PushContext(self.allContexts.Branches)
|
||||
return self.c.PushContext(self.getContexts().Branches)
|
||||
}
|
||||
|
||||
func (self *TagsController) enter(tag *models.Tag) error {
|
||||
@ -171,7 +171,7 @@ func (self *TagsController) CreateTagMenu(commitSha string) error {
|
||||
}
|
||||
|
||||
func (self *TagsController) afterTagCreate() error {
|
||||
self.context.GetPanelState().SetSelectedLineIdx(0)
|
||||
self.getContext().GetPanelState().SetSelectedLineIdx(0)
|
||||
return self.c.Refresh(types.RefreshOptions{
|
||||
Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS},
|
||||
})
|
||||
@ -225,5 +225,5 @@ func (self *TagsController) withSelectedTag(f func(tag *models.Tag) error) func(
|
||||
}
|
||||
|
||||
func (self *TagsController) Context() types.Context {
|
||||
return self.context
|
||||
return self.getContext()
|
||||
}
|
||||
|
@ -1,191 +1,182 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
// const diffForTest = `diff --git a/pkg/gui/diff_context_size.go b/pkg/gui/diff_context_size.go
|
||||
// index 0da0a982..742b7dcf 100644
|
||||
// --- a/pkg/gui/diff_context_size.go
|
||||
// +++ b/pkg/gui/diff_context_size.go
|
||||
// @@ -9,12 +9,12 @@ func getRefreshFunction(gui *Gui) func()error {
|
||||
// }
|
||||
// } else if key == MAIN_STAGING_CONTEXT_KEY {
|
||||
// return func() error {
|
||||
// - selectedLine := gui.Views.Secondary.SelectedLineIdx()
|
||||
// + selectedLine := gui.State.Panels.LineByLine.GetSelectedLineIdx()
|
||||
// return gui.handleRefreshStagingPanel(false, selectedLine)
|
||||
// }
|
||||
// } else if key == MAIN_PATCH_BUILDING_CONTEXT_KEY {
|
||||
// `
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/popup"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
// func setupGuiForTest(gui *Gui) {
|
||||
// gui.g = &gocui.Gui{}
|
||||
// gui.Views.Main, _ = gui.prepareView("main")
|
||||
// gui.Views.Secondary, _ = gui.prepareView("secondary")
|
||||
// gui.Views.Options, _ = gui.prepareView("options")
|
||||
// gui.git.Patch.PatchManager = &patch.PatchManager{}
|
||||
// _, _ = gui.refreshLineByLinePanel(diffForTest, "", false, 11)
|
||||
// }
|
||||
|
||||
const diffForTest = `diff --git a/pkg/gui/diff_context_size.go b/pkg/gui/diff_context_size.go
|
||||
index 0da0a982..742b7dcf 100644
|
||||
--- a/pkg/gui/diff_context_size.go
|
||||
+++ b/pkg/gui/diff_context_size.go
|
||||
@@ -9,12 +9,12 @@ func getRefreshFunction(gui *Gui) func()error {
|
||||
}
|
||||
} else if key == MAIN_STAGING_CONTEXT_KEY {
|
||||
return func() error {
|
||||
- selectedLine := gui.Views.Secondary.SelectedLineIdx()
|
||||
+ selectedLine := gui.State.Panels.LineByLine.GetSelectedLineIdx()
|
||||
return gui.handleRefreshStagingPanel(false, selectedLine)
|
||||
}
|
||||
} else if key == MAIN_PATCH_BUILDING_CONTEXT_KEY {
|
||||
`
|
||||
// func TestIncreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
|
||||
// contexts := []func(gui *Gui) types.Context{
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Files },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.BranchCommits },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.CommitFiles },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Stash },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Staging },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.PatchBuilding },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.SubCommits },
|
||||
// }
|
||||
|
||||
func setupGuiForTest(gui *Gui) {
|
||||
gui.g = &gocui.Gui{}
|
||||
gui.Views.Main, _ = gui.prepareView("main")
|
||||
gui.Views.Secondary, _ = gui.prepareView("secondary")
|
||||
gui.Views.Options, _ = gui.prepareView("options")
|
||||
gui.git.Patch.PatchManager = &patch.PatchManager{}
|
||||
_, _ = gui.refreshLineByLinePanel(diffForTest, "", false, 11)
|
||||
}
|
||||
// for _, c := range contexts {
|
||||
// gui := NewDummyGui()
|
||||
// context := c(gui)
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 1
|
||||
// _ = gui.c.PushContext(context)
|
||||
|
||||
func TestIncreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
|
||||
contexts := []func(gui *Gui) Context{
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Files },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.BranchCommits },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.CommitFiles },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Stash },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Staging },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.PatchBuilding },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.SubCommits },
|
||||
}
|
||||
// _ = gui.IncreaseContextInDiffView()
|
||||
|
||||
for _, c := range contexts {
|
||||
gui := NewDummyGui()
|
||||
context := c(gui)
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 1
|
||||
_ = gui.c.PushContext(context)
|
||||
// assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
// }
|
||||
// }
|
||||
|
||||
_ = gui.IncreaseContextInDiffView()
|
||||
// func TestDoesntIncreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
|
||||
// contexts := []func(gui *Gui) types.Context{
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Status },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Submodules },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Remotes },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Normal },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.ReflogCommits },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.RemoteBranches },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Tags },
|
||||
// // not testing this because it will kick straight back to the files context
|
||||
// // upon pushing the context
|
||||
// // func(gui *Gui) types.Context { return gui.State.Contexts.Merging },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.CommandLog },
|
||||
// }
|
||||
|
||||
assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
}
|
||||
}
|
||||
// for _, c := range contexts {
|
||||
// gui := NewDummyGui()
|
||||
// context := c(gui)
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 1
|
||||
// _ = gui.c.PushContext(context)
|
||||
|
||||
func TestDoesntIncreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
|
||||
contexts := []func(gui *Gui) Context{
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Status },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Submodules },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Remotes },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Normal },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.ReflogCommits },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.RemoteBranches },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Tags },
|
||||
// not testing this because it will kick straight back to the files context
|
||||
// upon pushing the context
|
||||
// func(gui *Gui) Context { return gui.State.Contexts.Merging },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.CommandLog },
|
||||
}
|
||||
// _ = gui.IncreaseContextInDiffView()
|
||||
|
||||
for _, c := range contexts {
|
||||
gui := NewDummyGui()
|
||||
context := c(gui)
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 1
|
||||
_ = gui.c.PushContext(context)
|
||||
// assert.Equal(t, 1, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
// }
|
||||
// }
|
||||
|
||||
_ = gui.IncreaseContextInDiffView()
|
||||
// func TestDecreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
|
||||
// contexts := []func(gui *Gui) types.Context{
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Files },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.BranchCommits },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.CommitFiles },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Stash },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Staging },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.PatchBuilding },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.SubCommits },
|
||||
// }
|
||||
|
||||
assert.Equal(t, 1, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
}
|
||||
}
|
||||
// for _, c := range contexts {
|
||||
// gui := NewDummyGui()
|
||||
// context := c(gui)
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
// _ = gui.c.PushContext(context)
|
||||
|
||||
func TestDecreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
|
||||
contexts := []func(gui *Gui) Context{
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Files },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.BranchCommits },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.CommitFiles },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Stash },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Staging },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.PatchBuilding },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.SubCommits },
|
||||
}
|
||||
// _ = gui.DecreaseContextInDiffView()
|
||||
|
||||
for _, c := range contexts {
|
||||
gui := NewDummyGui()
|
||||
context := c(gui)
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
_ = gui.c.PushContext(context)
|
||||
// assert.Equal(t, 1, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
// }
|
||||
// }
|
||||
|
||||
_ = gui.DecreaseContextInDiffView()
|
||||
// func TestDoesntDecreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
|
||||
// contexts := []func(gui *Gui) types.Context{
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Status },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Submodules },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Remotes },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Normal },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.ReflogCommits },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.RemoteBranches },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.Tags },
|
||||
// // not testing this because it will kick straight back to the files context
|
||||
// // upon pushing the context
|
||||
// // func(gui *Gui) types.Context { return gui.State.Contexts.Merging },
|
||||
// func(gui *Gui) types.Context { return gui.State.Contexts.CommandLog },
|
||||
// }
|
||||
|
||||
assert.Equal(t, 1, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
}
|
||||
}
|
||||
// for _, c := range contexts {
|
||||
// gui := NewDummyGui()
|
||||
// context := c(gui)
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
// _ = gui.c.PushContext(context)
|
||||
|
||||
func TestDoesntDecreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
|
||||
contexts := []func(gui *Gui) Context{
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Status },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Submodules },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Remotes },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Normal },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.ReflogCommits },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.RemoteBranches },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.Tags },
|
||||
// not testing this because it will kick straight back to the files context
|
||||
// upon pushing the context
|
||||
// func(gui *Gui) Context { return gui.State.Contexts.Merging },
|
||||
func(gui *Gui) Context { return gui.State.Contexts.CommandLog },
|
||||
}
|
||||
// _ = gui.DecreaseContextInDiffView()
|
||||
|
||||
for _, c := range contexts {
|
||||
gui := NewDummyGui()
|
||||
context := c(gui)
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
_ = gui.c.PushContext(context)
|
||||
// assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
// }
|
||||
// }
|
||||
|
||||
_ = gui.DecreaseContextInDiffView()
|
||||
// func TestDoesntIncreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *testing.T) {
|
||||
// gui := NewDummyGui()
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
// _ = gui.c.PushContext(gui.State.Contexts.CommitFiles)
|
||||
// gui.git.Patch.PatchManager.Start("from", "to", false, false)
|
||||
|
||||
assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize, string(context.GetKey()))
|
||||
}
|
||||
}
|
||||
// errorCount := 0
|
||||
// gui.PopupHandler = &popup.TestPopupHandler{
|
||||
// OnErrorMsg: func(message string) error {
|
||||
// assert.Equal(t, gui.c.Tr.CantChangeContextSizeError, message)
|
||||
// errorCount += 1
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
|
||||
func TestDoesntIncreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *testing.T) {
|
||||
gui := NewDummyGui()
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
_ = gui.c.PushContext(gui.State.Contexts.CommitFiles)
|
||||
gui.git.Patch.PatchManager.Start("from", "to", false, false)
|
||||
// _ = gui.IncreaseContextInDiffView()
|
||||
|
||||
errorCount := 0
|
||||
gui.PopupHandler = &popup.TestPopupHandler{
|
||||
OnErrorMsg: func(message string) error {
|
||||
assert.Equal(t, gui.c.Tr.CantChangeContextSizeError, message)
|
||||
errorCount += 1
|
||||
return nil
|
||||
},
|
||||
}
|
||||
// assert.Equal(t, 1, errorCount)
|
||||
// assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize)
|
||||
// }
|
||||
|
||||
_ = gui.IncreaseContextInDiffView()
|
||||
// func TestDoesntDecreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *testing.T) {
|
||||
// gui := NewDummyGui()
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
// _ = gui.c.PushContext(gui.State.Contexts.CommitFiles)
|
||||
// gui.git.Patch.PatchManager.Start("from", "to", false, false)
|
||||
|
||||
assert.Equal(t, 1, errorCount)
|
||||
assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize)
|
||||
}
|
||||
// errorCount := 0
|
||||
// gui.PopupHandler = &popup.TestPopupHandler{
|
||||
// OnErrorMsg: func(message string) error {
|
||||
// assert.Equal(t, gui.c.Tr.CantChangeContextSizeError, message)
|
||||
// errorCount += 1
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
|
||||
func TestDoesntDecreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *testing.T) {
|
||||
gui := NewDummyGui()
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 2
|
||||
_ = gui.c.PushContext(gui.State.Contexts.CommitFiles)
|
||||
gui.git.Patch.PatchManager.Start("from", "to", false, false)
|
||||
// _ = gui.DecreaseContextInDiffView()
|
||||
|
||||
errorCount := 0
|
||||
gui.PopupHandler = &popup.TestPopupHandler{
|
||||
OnErrorMsg: func(message string) error {
|
||||
assert.Equal(t, gui.c.Tr.CantChangeContextSizeError, message)
|
||||
errorCount += 1
|
||||
return nil
|
||||
},
|
||||
}
|
||||
// assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize)
|
||||
// }
|
||||
|
||||
_ = gui.DecreaseContextInDiffView()
|
||||
// func TestDecreasesContextInDiffViewNoFurtherThanOne(t *testing.T) {
|
||||
// gui := NewDummyGui()
|
||||
// setupGuiForTest(gui)
|
||||
// gui.c.UserConfig.Git.DiffContextSize = 1
|
||||
|
||||
assert.Equal(t, 2, gui.c.UserConfig.Git.DiffContextSize)
|
||||
}
|
||||
// _ = gui.DecreaseContextInDiffView()
|
||||
|
||||
func TestDecreasesContextInDiffViewNoFurtherThanOne(t *testing.T) {
|
||||
gui := NewDummyGui()
|
||||
setupGuiForTest(gui)
|
||||
gui.c.UserConfig.Git.DiffContextSize = 1
|
||||
|
||||
_ = gui.DecreaseContextInDiffView()
|
||||
|
||||
assert.Equal(t, 1, gui.c.UserConfig.Git.DiffContextSize)
|
||||
}
|
||||
// assert.Equal(t, 1, gui.c.UserConfig.Git.DiffContextSize)
|
||||
// }
|
||||
|
@ -301,23 +301,13 @@ func (gui *Gui) findNewSelectedIdx(prevNodes []*filetree.FileNode, currNodes []*
|
||||
|
||||
func (gui *Gui) onFocusFile() error {
|
||||
gui.takeOverMergeConflictScrolling()
|
||||
|
||||
if gui.State.Panels.Merging.GetPath() != file.Name {
|
||||
hasConflicts, err := gui.setMergeStateWithLock(file.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !hasConflicts {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this can't be right.
|
||||
return gui.pushContext(gui.State.Contexts.Merging)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) getSetTextareaTextFn(view *gocui.View) func(string) {
|
||||
func (gui *Gui) getSetTextareaTextFn(getView func() *gocui.View) func(string) {
|
||||
return func(text string) {
|
||||
// using a getView function so that we don't need to worry about when the view is created
|
||||
view := getView()
|
||||
view.ClearTextArea()
|
||||
view.TextArea.TypeString(text)
|
||||
view.RenderTextArea()
|
||||
|
@ -564,24 +564,34 @@ func NewGui(
|
||||
gui.c = controllerCommon
|
||||
|
||||
gui.resetState(filterPath, false)
|
||||
gui.setControllers()
|
||||
authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors)
|
||||
presentation.SetCustomBranches(gui.UserConfig.Gui.BranchColors)
|
||||
|
||||
return gui, nil
|
||||
}
|
||||
|
||||
func (gui *Gui) setControllers() {
|
||||
controllerCommon := gui.c
|
||||
osCommand := gui.OSCommand
|
||||
getState := func() *GuiRepoState { return gui.State }
|
||||
getContexts := func() context.ContextTree { return gui.State.Contexts }
|
||||
// TODO: have a getGit function too
|
||||
refHelper := NewRefHelper(
|
||||
controllerCommon,
|
||||
gui.git,
|
||||
gui.State,
|
||||
getState,
|
||||
)
|
||||
gui.refHelper = refHelper
|
||||
gui.suggestionsHelper = NewSuggestionsHelper(controllerCommon, gui.State, gui.refreshSuggestions)
|
||||
gui.suggestionsHelper = NewSuggestionsHelper(controllerCommon, getState, gui.refreshSuggestions)
|
||||
gui.fileHelper = NewFileHelper(controllerCommon, gui.git, osCommand)
|
||||
gui.workingTreeHelper = NewWorkingTreeHelper(gui.State.FileTreeViewModel)
|
||||
gui.workingTreeHelper = NewWorkingTreeHelper(func() *filetree.FileTreeViewModel { return gui.State.FileTreeViewModel })
|
||||
|
||||
tagsController := controllers.NewTagsController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Tags,
|
||||
func() types.IListContext { return gui.State.Contexts.Tags },
|
||||
gui.git,
|
||||
gui.State.Contexts,
|
||||
getContexts,
|
||||
refHelper,
|
||||
gui.suggestionsHelper,
|
||||
gui.getSelectedTag,
|
||||
@ -607,15 +617,15 @@ func NewGui(
|
||||
),
|
||||
Files: controllers.NewFilesController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Files,
|
||||
func() types.IListContext { return gui.State.Contexts.Files },
|
||||
gui.git,
|
||||
osCommand,
|
||||
gui.getSelectedFileNode,
|
||||
gui.State.Contexts,
|
||||
gui.State.FileTreeViewModel,
|
||||
getContexts,
|
||||
func() *filetree.FileTreeViewModel { return gui.State.FileTreeViewModel },
|
||||
gui.enterSubmodule,
|
||||
func() []*models.SubmoduleConfig { return gui.State.Submodules },
|
||||
gui.getSetTextareaTextFn(gui.Views.CommitMessage),
|
||||
gui.getSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitMessage }),
|
||||
gui.withGpgHandling,
|
||||
func() string { return gui.State.failedCommitMessage },
|
||||
func() []*models.Commit { return gui.State.Commits },
|
||||
@ -630,7 +640,7 @@ func NewGui(
|
||||
|
||||
LocalCommits: controllers.NewLocalCommitsController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.BranchCommits,
|
||||
func() types.IListContext { return gui.State.Contexts.BranchCommits },
|
||||
osCommand,
|
||||
gui.git,
|
||||
refHelper,
|
||||
@ -651,21 +661,21 @@ func NewGui(
|
||||
|
||||
Remotes: controllers.NewRemotesController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Remotes,
|
||||
func() types.IListContext { return gui.State.Contexts.Remotes },
|
||||
gui.git,
|
||||
gui.State.Contexts,
|
||||
getContexts,
|
||||
gui.getSelectedRemote,
|
||||
func(branches []*models.RemoteBranch) { gui.State.RemoteBranches = branches },
|
||||
gui.Mutexes.FetchMutex,
|
||||
),
|
||||
Menu: controllers.NewMenuController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.Menu,
|
||||
func() types.IListContext { return gui.State.Contexts.Menu },
|
||||
gui.getSelectedMenuItem,
|
||||
),
|
||||
Bisect: controllers.NewBisectController(
|
||||
controllerCommon,
|
||||
gui.State.Contexts.BranchCommits,
|
||||
func() types.IListContext { return gui.State.Contexts.BranchCommits },
|
||||
gui.git,
|
||||
gui.getSelectedLocalCommit,
|
||||
func() []*models.Commit { return gui.State.Commits },
|
||||
@ -679,8 +689,6 @@ func NewGui(
|
||||
),
|
||||
Sync: syncController,
|
||||
}
|
||||
|
||||
return gui, nil
|
||||
}
|
||||
|
||||
var RuneReplacements = map[rune]string{
|
||||
|
@ -1400,6 +1400,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
|
||||
gui.Controllers.Bisect,
|
||||
gui.Controllers.Undo,
|
||||
gui.Controllers.Sync,
|
||||
gui.Controllers.Tags,
|
||||
} {
|
||||
context := controller.Context()
|
||||
viewName := ""
|
||||
@ -1422,7 +1423,6 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
|
||||
for _, listContext := range []types.IListContext{
|
||||
gui.State.Contexts.Branches,
|
||||
gui.State.Contexts.RemoteBranches,
|
||||
gui.State.Contexts.Tags,
|
||||
gui.State.Contexts.ReflogCommits,
|
||||
gui.State.Contexts.SubCommits,
|
||||
gui.State.Contexts.Stash,
|
||||
|
@ -277,6 +277,7 @@ func (self *ListContext) Keybindings(
|
||||
{
|
||||
Key: getKey(config.Universal.GotoBottom),
|
||||
Description: self.Gui.c.Tr.LcGotoBottom,
|
||||
Handler: self.HandleGotoBottom,
|
||||
Tag: "navigation",
|
||||
},
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
package gui
|
||||
|
||||
import "github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
|
||||
// this file is to put things where it's not obvious where they belong while this refactor takes place
|
||||
|
||||
func (gui *Gui) getSuggestedRemote() string {
|
||||
remotes := gui.State.Remotes
|
||||
|
||||
return getSuggestedRemote(remotes)
|
||||
}
|
||||
|
||||
func getSuggestedRemote(remotes []*models.Remote) string {
|
||||
if len(remotes) == 0 {
|
||||
return "origin"
|
||||
}
|
||||
|
@ -212,6 +212,8 @@ type TestPopupHandler struct {
|
||||
OnPrompt func(opts PromptOpts) error
|
||||
}
|
||||
|
||||
var _ IPopupHandler = &TestPopupHandler{}
|
||||
|
||||
func (self *TestPopupHandler) Error(err error) error {
|
||||
return self.ErrorMsg(err.Error())
|
||||
}
|
||||
@ -244,6 +246,6 @@ func (self *TestPopupHandler) Toast(message string) {
|
||||
panic("not yet implemented")
|
||||
}
|
||||
|
||||
func (self *TestPopupHandler) CurrentInput() string {
|
||||
func (self *TestPopupHandler) GetPromptInput() string {
|
||||
panic("not yet implemented")
|
||||
}
|
||||
|
@ -16,18 +16,18 @@ type RefHelper struct {
|
||||
c *controllers.ControllerCommon
|
||||
git *commands.GitCommand
|
||||
|
||||
State *GuiRepoState
|
||||
getState func() *GuiRepoState
|
||||
}
|
||||
|
||||
func NewRefHelper(
|
||||
c *controllers.ControllerCommon,
|
||||
git *commands.GitCommand,
|
||||
state *GuiRepoState,
|
||||
getState func() *GuiRepoState,
|
||||
) *RefHelper {
|
||||
return &RefHelper{
|
||||
c: c,
|
||||
git: git,
|
||||
State: state,
|
||||
c: c,
|
||||
git: git,
|
||||
getState: getState,
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,10 +42,10 @@ func (self *RefHelper) CheckoutRef(ref string, options types.CheckoutRefOptions)
|
||||
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
||||
|
||||
onSuccess := func() {
|
||||
self.State.Panels.Branches.SelectedLineIdx = 0
|
||||
self.State.Panels.Commits.SelectedLineIdx = 0
|
||||
self.getState().Panels.Branches.SelectedLineIdx = 0
|
||||
self.getState().Panels.Commits.SelectedLineIdx = 0
|
||||
// loading a heap of commits is slow so we limit them whenever doing a reset
|
||||
self.State.Panels.Commits.LimitCommits = true
|
||||
self.getState().Panels.Commits.LimitCommits = true
|
||||
}
|
||||
|
||||
return self.c.WithWaitingStatus(waitingStatus, func() error {
|
||||
@ -97,12 +97,12 @@ func (self *RefHelper) ResetToRef(ref string, strength string, envVars []string)
|
||||
return self.c.Error(err)
|
||||
}
|
||||
|
||||
self.State.Panels.Commits.SelectedLineIdx = 0
|
||||
self.State.Panels.ReflogCommits.SelectedLineIdx = 0
|
||||
self.getState().Panels.Commits.SelectedLineIdx = 0
|
||||
self.getState().Panels.ReflogCommits.SelectedLineIdx = 0
|
||||
// loading a heap of commits is slow so we limit them whenever doing a reset
|
||||
self.State.Panels.Commits.LimitCommits = true
|
||||
self.getState().Panels.Commits.LimitCommits = true
|
||||
|
||||
if err := self.c.PushContext(self.State.Contexts.BranchCommits); err != nil {
|
||||
if err := self.c.PushContext(self.getState().Contexts.BranchCommits); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
type SuggestionsHelper struct {
|
||||
c *controllers.ControllerCommon
|
||||
|
||||
State *GuiRepoState
|
||||
getState func() *GuiRepoState
|
||||
refreshSuggestionsFn func()
|
||||
}
|
||||
|
||||
@ -33,19 +33,19 @@ var _ controllers.ISuggestionsHelper = &SuggestionsHelper{}
|
||||
|
||||
func NewSuggestionsHelper(
|
||||
c *controllers.ControllerCommon,
|
||||
state *GuiRepoState,
|
||||
getState func() *GuiRepoState,
|
||||
refreshSuggestionsFn func(),
|
||||
) *SuggestionsHelper {
|
||||
return &SuggestionsHelper{
|
||||
c: c,
|
||||
State: state,
|
||||
getState: getState,
|
||||
refreshSuggestionsFn: refreshSuggestionsFn,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SuggestionsHelper) getRemoteNames() []string {
|
||||
result := make([]string, len(self.State.Remotes))
|
||||
for i, remote := range self.State.Remotes {
|
||||
result := make([]string, len(self.getState().Remotes))
|
||||
for i, remote := range self.getState().Remotes {
|
||||
result[i] = remote.Name
|
||||
}
|
||||
return result
|
||||
@ -69,8 +69,8 @@ func (self *SuggestionsHelper) GetRemoteSuggestionsFunc() func(string) []*types.
|
||||
}
|
||||
|
||||
func (self *SuggestionsHelper) getBranchNames() []string {
|
||||
result := make([]string, len(self.State.Branches))
|
||||
for i, branch := range self.State.Branches {
|
||||
result := make([]string, len(self.getState().Branches))
|
||||
for i, branch := range self.getState().Branches {
|
||||
result[i] = branch.Name
|
||||
}
|
||||
return result
|
||||
@ -123,7 +123,7 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type
|
||||
return nil
|
||||
})
|
||||
// cache the trie for future use
|
||||
self.State.FilesTrie = trie
|
||||
self.getState().FilesTrie = trie
|
||||
|
||||
self.refreshSuggestionsFn()
|
||||
|
||||
@ -132,7 +132,7 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type
|
||||
|
||||
return func(input string) []*types.Suggestion {
|
||||
matchingNames := []string{}
|
||||
_ = self.State.FilesTrie.VisitFuzzy(patricia.Prefix(input), true, func(prefix patricia.Prefix, item patricia.Item, skipped int) error {
|
||||
_ = self.getState().FilesTrie.VisitFuzzy(patricia.Prefix(input), true, func(prefix patricia.Prefix, item patricia.Item, skipped int) error {
|
||||
matchingNames = append(matchingNames, item.(string))
|
||||
return nil
|
||||
})
|
||||
@ -154,7 +154,7 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type
|
||||
|
||||
func (self *SuggestionsHelper) getRemoteBranchNames(separator string) []string {
|
||||
result := []string{}
|
||||
for _, remote := range self.State.Remotes {
|
||||
for _, remote := range self.getState().Remotes {
|
||||
for _, branch := range remote.Branches {
|
||||
result = append(result, fmt.Sprintf("%s%s%s", remote.Name, separator, branch.Name))
|
||||
}
|
||||
@ -167,8 +167,8 @@ func (self *SuggestionsHelper) GetRemoteBranchesSuggestionsFunc(separator string
|
||||
}
|
||||
|
||||
func (self *SuggestionsHelper) getTagNames() []string {
|
||||
result := make([]string, len(self.State.Tags))
|
||||
for i, tag := range self.State.Tags {
|
||||
result := make([]string, len(self.getState().Tags))
|
||||
for i, tag := range self.getState().Tags {
|
||||
result[i] = tag.Name
|
||||
}
|
||||
return result
|
||||
|
@ -6,17 +6,17 @@ import (
|
||||
)
|
||||
|
||||
type WorkingTreeHelper struct {
|
||||
fileTreeViewModel *filetree.FileTreeViewModel
|
||||
getFileTreeViewModel func() *filetree.FileTreeViewModel
|
||||
}
|
||||
|
||||
func NewWorkingTreeHelper(fileTreeViewModel *filetree.FileTreeViewModel) *WorkingTreeHelper {
|
||||
func NewWorkingTreeHelper(getFileTreeViewModel func() *filetree.FileTreeViewModel) *WorkingTreeHelper {
|
||||
return &WorkingTreeHelper{
|
||||
fileTreeViewModel: fileTreeViewModel,
|
||||
getFileTreeViewModel: getFileTreeViewModel,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *WorkingTreeHelper) AnyStagedFiles() bool {
|
||||
files := self.fileTreeViewModel.GetAllFiles()
|
||||
files := self.getFileTreeViewModel().GetAllFiles()
|
||||
for _, file := range files {
|
||||
if file.HasStagedChanges {
|
||||
return true
|
||||
@ -26,7 +26,7 @@ func (self *WorkingTreeHelper) AnyStagedFiles() bool {
|
||||
}
|
||||
|
||||
func (self *WorkingTreeHelper) AnyTrackedFiles() bool {
|
||||
files := self.fileTreeViewModel.GetAllFiles()
|
||||
files := self.getFileTreeViewModel().GetAllFiles()
|
||||
for _, file := range files {
|
||||
if file.Tracked {
|
||||
return true
|
||||
@ -40,7 +40,7 @@ func (self *WorkingTreeHelper) IsWorkingTreeDirty() bool {
|
||||
}
|
||||
|
||||
func (self *WorkingTreeHelper) FileForSubmodule(submodule *models.SubmoduleConfig) *models.File {
|
||||
for _, file := range self.fileTreeViewModel.GetAllFiles() {
|
||||
for _, file := range self.getFileTreeViewModel().GetAllFiles() {
|
||||
if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) {
|
||||
return file
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ func chineseTranslationSet() TranslationSet {
|
||||
LcScroll: "滚动",
|
||||
MergeConflictsTitle: "合并冲突",
|
||||
LcCheckout: "检出",
|
||||
LcCommitFileFilter: "过滤提交文件",
|
||||
NoChangedFiles: "没有更改过文件",
|
||||
NoFilesDisplay: "没有文件可显示",
|
||||
NotAFile: "不是文件",
|
||||
|
@ -33,7 +33,6 @@ func dutchTranslationSet() TranslationSet {
|
||||
LcPush: "push",
|
||||
LcPull: "pull",
|
||||
LcScroll: "scroll",
|
||||
LcCommitFileFilter: "Commit dossiers filteren",
|
||||
FilterStagedFiles: "Show only staged files",
|
||||
FilterUnstagedFiles: "Show only unstaged files",
|
||||
ResetCommitFilterState: "Reset commit file state filter",
|
||||
|
@ -47,7 +47,6 @@ type TranslationSet struct {
|
||||
LcPull string
|
||||
LcScroll string
|
||||
LcFileFilter string
|
||||
LcCommitFileFilter string
|
||||
FilterStagedFiles string
|
||||
FilterUnstagedFiles string
|
||||
ResetCommitFilterState string
|
||||
@ -622,7 +621,6 @@ func EnglishTranslationSet() TranslationSet {
|
||||
MergeConflictsTitle: "Merge Conflicts",
|
||||
LcCheckout: "checkout",
|
||||
LcFileFilter: "Filter files (staged/unstaged)",
|
||||
LcCommitFileFilter: "Filter commit files",
|
||||
FilterStagedFiles: "Show only staged files",
|
||||
FilterUnstagedFiles: "Show only unstaged files",
|
||||
ResetCommitFilterState: "Reset filter",
|
||||
|
@ -29,7 +29,6 @@ func polishTranslationSet() TranslationSet {
|
||||
LcToggleStagedAll: "przełącz stan poczekalni wszystkich",
|
||||
LcRefresh: "odśwież",
|
||||
LcScroll: "przewiń",
|
||||
LcCommitFileFilter: "Filtrowanie commitów",
|
||||
FilterStagedFiles: "Pokaż tylko pliki w poczekalni",
|
||||
FilterUnstagedFiles: "Pokaż tylko pliki poza poczekalnią",
|
||||
ResetCommitFilterState: "Resetuj filtr commitów",
|
||||
|
Reference in New Issue
Block a user