2019-03-09 16:42:10 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2022-01-16 05:46:53 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
|
2022-06-13 03:01:26 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2019-03-09 16:42:10 +02:00
|
|
|
)
|
|
|
|
|
2021-11-21 03:48:49 +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
|
2019-03-09 16:42:10 +02:00
|
|
|
}
|
|
|
|
|
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())
|
2020-08-22 10:29:09 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
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-06-13 03:01:26 +02:00
|
|
|
pair := gui.normalMainContextPair()
|
2022-02-05 07:56:36 +02:00
|
|
|
if node.File != nil {
|
2022-06-13 03:01:26 +02:00
|
|
|
pair = gui.patchBuildingMainContextPair()
|
2022-02-05 07:56:36 +02:00
|
|
|
}
|
|
|
|
|
2020-08-23 01:46:28 +02:00
|
|
|
return gui.refreshMainViews(refreshMainOpts{
|
2022-06-13 03:01:26 +02:00
|
|
|
pair: pair,
|
2020-08-18 14:02:35 +02:00
|
|
|
main: &viewUpdateOpts{
|
2022-06-13 03:01:26 +02:00
|
|
|
title: gui.Tr.Patch,
|
|
|
|
task: task,
|
2020-08-18 14:02:35 +02:00
|
|
|
},
|
|
|
|
secondary: gui.secondaryPatchPanelUpdateOpts(),
|
|
|
|
})
|
2019-03-09 16:42:10 +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())
|
2019-03-11 04:04:08 +02:00
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
if err := gui.c.Refresh(types.RefreshOptions{
|
|
|
|
Scope: []types.RefreshableView{types.COMMIT_FILES},
|
|
|
|
}); err != nil {
|
2019-11-05 02:53:01 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-22 11:13:11 +02:00
|
|
|
return gui.c.PushContext(gui.State.Contexts.CommitFiles)
|
2019-03-11 04:04:08 +02:00
|
|
|
}
|