1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/commit_files_panel.go

79 lines
2.2 KiB
Go
Raw Normal View History

package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
)
2022-02-05 08:04:10 +02:00
// TODO: do we need this?
func (gui *Gui) onCommitFileFocus() error {
gui.escapeLineByLinePanel()
return nil
}
2019-11-10 07:20:35 +02:00
func (gui *Gui) commitFilesRenderToMain() error {
2022-03-19 00:31:52 +02:00
node := gui.State.Contexts.CommitFiles.GetSelected()
2021-03-31 13:08:55 +02:00
if node == nil {
2020-03-09 02:34:10 +02:00
return nil
}
2022-03-26 15:18:08 +02:00
ref := gui.State.Contexts.CommitFiles.GetRef()
to := ref.RefName()
from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
cmdObj := gui.git.WorkingTree.ShowFileDiffCmdObj(from, to, reverse, node.GetPath(), false)
2021-12-07 12:59:36 +02:00
task := NewRunPtyTask(cmdObj.GetCmd())
2020-08-18 14:02:35 +02:00
2022-02-05 07:56:36 +02:00
mainContext := gui.State.Contexts.Normal
if node.File != nil {
mainContext = gui.State.Contexts.PatchBuilding
}
2020-08-23 01:46:28 +02:00
return gui.refreshMainViews(refreshMainOpts{
2020-08-18 14:02:35 +02:00
main: &viewUpdateOpts{
2022-02-05 07:56:36 +02:00
title: "Patch",
task: task,
context: mainContext,
2020-08-18 14:02:35 +02:00
},
secondary: gui.secondaryPatchPanelUpdateOpts(),
})
}
2022-02-22 11:13:11 +02:00
func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesContextOpts) error {
gui.State.Contexts.CommitFiles.SetSelectedLineIdx(0)
2022-03-26 15:18:08 +02:00
gui.State.Contexts.CommitFiles.SetRef(opts.Ref)
2022-04-01 13:03:08 +02:00
gui.State.Contexts.CommitFiles.SetTitleRef(opts.Ref.Description())
2022-02-22 11:13:11 +02:00
gui.State.Contexts.CommitFiles.SetCanRebase(opts.CanRebase)
gui.State.Contexts.CommitFiles.SetParentContext(opts.Context)
gui.State.Contexts.CommitFiles.SetWindowName(opts.Context.GetWindowName())
if err := gui.refreshCommitFilesContext(); err != nil {
return err
}
2022-02-22 11:13:11 +02:00
return gui.c.PushContext(gui.State.Contexts.CommitFiles)
}
func (gui *Gui) refreshCommitFilesContext() error {
2022-03-26 15:18:08 +02:00
ref := gui.State.Contexts.CommitFiles.GetRef()
to := ref.RefName()
from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
files, err := gui.git.Loaders.CommitFiles.GetFilesInDiff(from, to, reverse)
if err != nil {
return gui.c.Error(err)
}
2022-01-31 13:11:34 +02:00
gui.State.Model.CommitFiles = files
gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.SetTree()
return gui.c.PostRefreshUpdate(gui.State.Contexts.CommitFiles)
2020-08-19 10:41:57 +02:00
}
2022-02-22 11:13:11 +02:00
func (gui *Gui) getSelectedCommitFileName() string {
2022-03-19 00:31:52 +02:00
node := gui.State.Contexts.CommitFiles.GetSelected()
2021-03-31 13:08:55 +02:00
if node == nil {
2022-02-22 11:13:11 +02:00
return ""
2020-08-21 11:53:45 +02:00
}
2022-02-22 11:13:11 +02:00
return node.Path
2020-08-21 11:53:45 +02:00
}