1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

fix some things

This commit is contained in:
Jesse Duffield 2022-01-23 14:40:28 +11:00
parent 1dd7307fde
commit a2318d75b5
30 changed files with 367 additions and 428 deletions

View File

@ -10,21 +10,20 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>pgdown</kbd>: scroll down main panel (fn+down)
<kbd>m</kbd>: view merge/rebase options
<kbd>ctrl+p</kbd>: view custom patch options
<kbd>P</kbd>: push
<kbd>p</kbd>: pull
<kbd>R</kbd>: refresh
<kbd>x</kbd>: open menu
<kbd>z</kbd>: undo (via reflog) (experimental)
<kbd>ctrl+z</kbd>: redo (via reflog) (experimental)
<kbd>+</kbd>: next screen mode (normal/half/fullscreen)
<kbd>_</kbd>: prev screen mode
<kbd>:</kbd>: execute custom command
<kbd>ctrl+s</kbd>: view filter-by-path options
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
<kbd>z</kbd>: undo (via reflog) (experimental)
<kbd>ctrl+z</kbd>: redo (via reflog) (experimental)
<kbd>P</kbd>: push
<kbd>p</kbd>: pull
</pre>
## List Panel Navigation
@ -170,20 +169,20 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>@</kbd>: open command log menu
</pre>
## Files Panel
<pre>
<kbd>ctrl+b</kbd>: Filter commit files
</pre>
## Files Panel (Files)
<pre>
<kbd>d</kbd>: view 'discard changes' options
<kbd>D</kbd>: view reset options
<kbd>f</kbd>: fetch
<kbd>ctrl+o</kbd>: copy the file name to the clipboard
<kbd>ctrl+w</kbd>: Toggle whether or not whitespace changes are shown in the diff view
<kbd>space</kbd>: toggle staged
<kbd>ctrl+b</kbd>: Filter files (staged/unstaged)
<kbd>c</kbd>: commit changes
<kbd>w</kbd>: commit changes without pre-commit hook
<kbd>A</kbd>: amend last commit
<kbd>C</kbd>: commit changes using git editor
<kbd>d</kbd>: view 'discard changes' options
<kbd>e</kbd>: edit file
<kbd>o</kbd>: open file
<kbd>i</kbd>: add to .gitignore
@ -191,15 +190,11 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>s</kbd>: stash changes
<kbd>S</kbd>: view stash options
<kbd>a</kbd>: stage/unstage all
<kbd>D</kbd>: view reset options
<kbd>enter</kbd>: stage individual hunks/lines for file, or collapse/expand for directory
<kbd>f</kbd>: fetch
<kbd>ctrl+o</kbd>: copy the file name to the clipboard
<kbd>:</kbd>: execute custom command
<kbd>g</kbd>: view upstream reset options
<kbd>`</kbd>: toggle file tree view
<kbd>M</kbd>: open external merge tool (git mergetool)
<kbd>ctrl+w</kbd>: Toggle whether or not whitespace changes are shown in the diff view
<kbd>space</kbd>: toggle staged
</pre>
## Files Panel (Submodules)

View File

@ -10,12 +10,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>pgdown</kbd>: scroll naar beneden vanaf hoofdpaneel (fn+down)
<kbd>m</kbd>: bekijk merge/rebase opties
<kbd>ctrl+p</kbd>: bekijk aangepaste patch opties
<kbd>P</kbd>: push
<kbd>p</kbd>: pull
<kbd>R</kbd>: verversen
<kbd>x</kbd>: open menu
<kbd>z</kbd>: ongedaan maken (via reflog) (experimenteel)
<kbd>ctrl+z</kbd>: redo (via reflog) (experimenteel)
<kbd>+</kbd>: volgende scherm modus (normaal/half/groot)
<kbd>_</kbd>: vorige scherm modus
<kbd>:</kbd>: voer aangepaste commando uit
@ -25,6 +21,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
<kbd>z</kbd>: ongedaan maken (via reflog) (experimenteel)
<kbd>ctrl+z</kbd>: redo (via reflog) (experimenteel)
<kbd>P</kbd>: push
<kbd>p</kbd>: pull
</pre>
## Lijstpaneel Navigatie
@ -170,12 +170,6 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>@</kbd>: open command log menu
</pre>
## Bestanden Paneel
<pre>
<kbd>ctrl+b</kbd>: Commit dossiers filteren
</pre>
## Bestanden Paneel (Bestanden)
<pre>
@ -183,7 +177,6 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>w</kbd>: commit veranderingen zonder pre-commit hook
<kbd>A</kbd>: wijzig laatste commit
<kbd>C</kbd>: commit veranderingen met de git editor
<kbd>d</kbd>: bekijk 'veranderingen ongedaan maken' opties
<kbd>e</kbd>: verander bestand
<kbd>o</kbd>: open bestand
<kbd>i</kbd>: voeg toe aan .gitignore
@ -191,15 +184,11 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>s</kbd>: stash-bestanden
<kbd>S</kbd>: bekijk stash opties
<kbd>a</kbd>: toggle staged alle
<kbd>D</kbd>: bekijk reset opties
<kbd>enter</kbd>: stage individuele hunks/lijnen
<kbd>f</kbd>: fetch
<kbd>ctrl+o</kbd>: kopieer de bestandsnaam naar het klembord
<kbd>:</kbd>: voor aangepaste commando uit
<kbd>g</kbd>: bekijk upstream reset opties
<kbd>`</kbd>: toggle bestandsboom weergave
<kbd>M</kbd>: open external merge tool (git mergetool)
<kbd>ctrl+w</kbd>: Toggle whether or not whitespace changes are shown in the diff view
<kbd>space</kbd>: toggle staged
</pre>
## Bestanden Paneel (Submodules)

View File

@ -10,21 +10,20 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>pgdown</kbd>: scroll down main panel (fn+down)
<kbd>m</kbd>: widok scalenia/opcje zmiany bazy
<kbd>ctrl+p</kbd>: view custom patch options
<kbd>P</kbd>: push
<kbd>p</kbd>: pull
<kbd>R</kbd>: odśwież
<kbd>x</kbd>: open menu
<kbd>z</kbd>: undo (via reflog) (experimental)
<kbd>ctrl+z</kbd>: redo (via reflog) (experimental)
<kbd>+</kbd>: next screen mode (normal/half/fullscreen)
<kbd>_</kbd>: prev screen mode
<kbd>:</kbd>: wykonaj własną komendę
<kbd>ctrl+s</kbd>: view filter-by-path options
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
<kbd>z</kbd>: undo (via reflog) (experimental)
<kbd>ctrl+z</kbd>: redo (via reflog) (experimental)
<kbd>P</kbd>: push
<kbd>p</kbd>: pull
</pre>
## List Panel Navigation
@ -170,20 +169,20 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>@</kbd>: open command log menu
</pre>
## Pliki Panel
<pre>
<kbd>ctrl+b</kbd>: Filtrowanie commitów
</pre>
## Pliki Panel (Pliki)
<pre>
<kbd>d</kbd>: pokaż opcje porzucania zmian
<kbd>D</kbd>: wyświetl opcje resetu
<kbd>f</kbd>: pobierz
<kbd>ctrl+o</kbd>: copy the file name to the clipboard
<kbd>ctrl+w</kbd>: Toggle whether or not whitespace changes are shown in the diff view
<kbd>space</kbd>: przełącz stan poczekalni
<kbd>ctrl+b</kbd>: Filter files (staged/unstaged)
<kbd>c</kbd>: Zatwierdź zmiany
<kbd>w</kbd>: zatwierdź zmiany bez skryptu pre-commit
<kbd>A</kbd>: Zmień ostatni commit
<kbd>C</kbd>: Zatwierdź zmiany używając edytora
<kbd>d</kbd>: pokaż opcje porzucania zmian
<kbd>e</kbd>: edytuj plik
<kbd>o</kbd>: otwórz plik
<kbd>i</kbd>: dodaj do .gitignore
@ -191,15 +190,11 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>s</kbd>: przechowaj zmiany
<kbd>S</kbd>: wyświetl opcje schowka
<kbd>a</kbd>: przełącz stan poczekalni wszystkich
<kbd>D</kbd>: wyświetl opcje resetu
<kbd>enter</kbd>: zatwierdź pojedyncze linie
<kbd>f</kbd>: pobierz
<kbd>ctrl+o</kbd>: copy the file name to the clipboard
<kbd>:</kbd>: wykonaj własną komendę
<kbd>g</kbd>: view upstream reset options
<kbd>`</kbd>: toggle file tree view
<kbd>M</kbd>: open external merge tool (git mergetool)
<kbd>ctrl+w</kbd>: Toggle whether or not whitespace changes are shown in the diff view
<kbd>space</kbd>: przełącz stan poczekalni
</pre>
## Pliki Panel (Submodules)

View File

@ -10,21 +10,20 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>pgdown</kbd>: 向下滚动主面板 (fn+down)
<kbd>m</kbd>: 查看 合并/变基 选项
<kbd>ctrl+p</kbd>: 查看自定义补丁选项
<kbd>P</kbd>: 推送
<kbd>p</kbd>: 拉取
<kbd>R</kbd>: 刷新
<kbd>x</kbd>: 打开菜单
<kbd>z</kbd>: (通过 reflog)撤销「实验功能」
<kbd>ctrl+z</kbd>: (通过 reflog)重做「实验功能」
<kbd>+</kbd>: 下一屏模式(正常/半屏/全屏)
<kbd>_</kbd>: 上一屏模式
<kbd>:</kbd>: 执行自定义命令
<kbd>ctrl+s</kbd>: 查看按路径过滤选项
<kbd>W</kbd>: 打开 diff 菜单
<kbd>ctrl+e</kbd>: 打开 diff 菜单
<kbd>@</kbd>: 打开命令日志菜单
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
<kbd>z</kbd>: (通过 reflog)撤销「实验功能」
<kbd>ctrl+z</kbd>: (通过 reflog)重做「实验功能」
<kbd>P</kbd>: 推送
<kbd>p</kbd>: 拉取
</pre>
## 列表面板导航
@ -170,20 +169,20 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>@</kbd>: 打开命令日志菜单
</pre>
## 文件 面板
<pre>
<kbd>ctrl+b</kbd>: 过滤提交文件
</pre>
## 文件 面板 (文件)
<pre>
<kbd>d</kbd>: 查看'放弃更改‘选项
<kbd>D</kbd>: 查看重置选项
<kbd>f</kbd>: 抓取
<kbd>ctrl+o</kbd>: 将文件名复制到剪贴板
<kbd>ctrl+w</kbd>: 切换是否在差异视图中显示空白更改
<kbd>space</kbd>: 切换暂存状态
<kbd>ctrl+b</kbd>: Filter files (staged/unstaged)
<kbd>c</kbd>: 提交更改
<kbd>w</kbd>: 提交更改而无需预先提交钩子
<kbd>A</kbd>: 修补最后一次提交
<kbd>C</kbd>: 提交更改(使用编辑器编辑提交信息)
<kbd>d</kbd>: 查看'放弃更改‘选项
<kbd>e</kbd>: 编辑文件
<kbd>o</kbd>: 打开文件
<kbd>i</kbd>: 添加到 .gitignore
@ -191,15 +190,11 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>s</kbd>: 将所有更改加入贮藏
<kbd>S</kbd>: 查看隐藏选项
<kbd>a</kbd>: 切换所有文件的暂存状态
<kbd>D</kbd>: 查看重置选项
<kbd>enter</kbd>: 暂存单个 块/行 用于文件, 或 折叠/展开 目录
<kbd>f</kbd>: 抓取
<kbd>ctrl+o</kbd>: 将文件名复制到剪贴板
<kbd>:</kbd>: 执行自定义命令
<kbd>g</kbd>: 查看上游重置选项
<kbd>`</kbd>: 切换文件树视图
<kbd>M</kbd>: 打开合并工具
<kbd>ctrl+w</kbd>: 切换是否在差异视图中显示空白更改
<kbd>space</kbd>: 切换暂存状态
</pre>
## 文件 面板 (子模块)

2
go.mod
View File

@ -14,7 +14,6 @@ require (
github.com/gdamore/tcell/v2 v2.4.1-0.20220313203054-2a1a1b586447 // indirect
github.com/go-errors/errors v1.4.1
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/gookit/color v1.4.2
@ -45,6 +44,5 @@ require (
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ozeidan/fuzzy-patricia.v3 v3.0.0
)

3
go.sum
View File

@ -33,7 +33,6 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM=
github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/gdamore/tcell/v2 v2.4.1-0.20210926162909-66f061b1fc9b h1:eoaSI4eEwM5eTx/HvmRSwmicxuMhL73AyoEfM1oCJLc=
github.com/gdamore/tcell/v2 v2.4.1-0.20210926162909-66f061b1fc9b/go.mod h1:ZPwXnysybtQqdqKcWMWXux9aGdtMHe+kr+cwEZEe+A4=
@ -55,8 +54,6 @@ github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)
// }

View File

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

View File

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

View File

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

View File

@ -277,6 +277,7 @@ func (self *ListContext) Keybindings(
{
Key: getKey(config.Universal.GotoBottom),
Description: self.Gui.c.Tr.LcGotoBottom,
Handler: self.HandleGotoBottom,
Tag: "navigation",
},
}

View File

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

View File

@ -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")
}

View File

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

View File

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

View File

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

View File

@ -66,7 +66,6 @@ func chineseTranslationSet() TranslationSet {
LcScroll: "滚动",
MergeConflictsTitle: "合并冲突",
LcCheckout: "检出",
LcCommitFileFilter: "过滤提交文件",
NoChangedFiles: "没有更改过文件",
NoFilesDisplay: "没有文件可显示",
NotAFile: "不是文件",

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
{
"description": "Verify that when we get merge conflicts we filter out any non-conflicted files",
"speed": 20
"speed": 1
}

3
vendor/modules.txt vendored
View File

@ -100,8 +100,6 @@ github.com/gobwas/glob/syntax/ast
github.com/gobwas/glob/syntax/lexer
github.com/gobwas/glob/util/runes
github.com/gobwas/glob/util/strings
# github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
## explicit
# github.com/golang/protobuf v1.3.2
## explicit
# github.com/google/go-cmp v0.5.6
@ -268,7 +266,6 @@ golang.org/x/sys/windows
## explicit
golang.org/x/term
# golang.org/x/text v0.3.7
## explicit
golang.org/x/text/encoding
golang.org/x/text/encoding/internal/identifier
golang.org/x/text/transform