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"
|
2019-03-09 16:42:10 +02:00
|
|
|
)
|
|
|
|
|
2022-02-05 08:04:10 +02:00
|
|
|
// TODO: do we need this?
|
2021-11-21 03:48:49 +02:00
|
|
|
func (gui *Gui) onCommitFileFocus() error {
|
2020-10-01 23:56:14 +02:00
|
|
|
gui.escapeLineByLinePanel()
|
2021-11-21 03:48:49 +02:00
|
|
|
return nil
|
|
|
|
}
|
2019-11-10 07:20:35 +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-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(),
|
|
|
|
})
|
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-03-24 13:07:30 +02:00
|
|
|
if err := gui.refreshCommitFilesContext(); 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
|
|
|
}
|
|
|
|
|
2022-03-24 13:07:30 +02:00
|
|
|
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())
|
2020-08-22 05:03:20 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
files, err := gui.git.Loaders.CommitFiles.GetFilesInDiff(from, to, reverse)
|
2019-03-11 04:04:08 +02:00
|
|
|
if err != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Error(err)
|
2019-03-11 04:04:08 +02:00
|
|
|
}
|
2022-01-31 13:11:34 +02:00
|
|
|
gui.State.Model.CommitFiles = files
|
2022-01-30 07:38:07 +02:00
|
|
|
gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.SetTree()
|
2019-03-11 04:04:08 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
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
|
|
|
}
|