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

53 lines
1.5 KiB
Go
Raw Normal View History

package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
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,
gui.IgnoreWhitespaceInDiffView)
task := types.NewRunPtyTask(cmdObj.GetCmd())
2020-08-18 14:02:35 +02:00
pair := gui.c.MainViewPairs().Normal
2022-02-05 07:56:36 +02:00
if node.File != nil {
pair = gui.c.MainViewPairs().PatchBuilding
2022-02-05 07:56:36 +02:00
}
return gui.c.RenderToMainViews(types.RefreshMainOpts{
Pair: pair,
Main: &types.ViewUpdateOpts{
Title: gui.Tr.Patch,
Task: task,
2020-08-18 14:02:35 +02:00
},
Secondary: gui.secondaryPatchPanelUpdateOpts(),
2020-08-18 14:02:35 +02:00
})
}
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.c.Refresh(types.RefreshOptions{
Scope: []types.RefreshableView{types.COMMIT_FILES},
}); err != nil {
return err
}
2022-02-22 11:13:11 +02:00
return gui.c.PushContext(gui.State.Contexts.CommitFiles)
}