mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-06 05:57:38 -04:00
A diff renderer may lay a diff out however it likes: line numbers in a gutter, the +/- column replaced by colour, the two sides in columns. Once it has, we can only tell which line of which file a row shows if the renderer says so. Under a renderer that doesn't say, the main view holds a diff that can be read but not staged, edited or copied from. That is no good now that the main view is where you stage. So focusing it brings git's own diff instead, and every re-render while it stays focused keeps to that, so staging a hunk doesn't flip back. Browsing is untouched: you see what the renderer produced until you focus the view to act on it. Whether the renderer says anything is settled by asking it rather than by watching it work: run it on empty input and see whether it announces the protocol. Announcing is a property of the renderer, so the answer is known before we render anything, and a diff with no lines to describe can't fool it. Watching would have to see a diff go by first, and a binary file's diff holds nothing that would tell the two cases apart. The answer is remembered until the renderer changes. git itself is asked the same question, with the renderer's own arguments, since it announces itself for exactly the formats whose output can't be read back as a diff. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type ReflogCommitsController struct {
|
|
baseController
|
|
*ListControllerTrait[*models.Commit]
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &ReflogCommitsController{}
|
|
|
|
func NewReflogCommitsController(
|
|
c *ControllerCommon,
|
|
) *ReflogCommitsController {
|
|
return &ReflogCommitsController{
|
|
baseController: baseController{},
|
|
ListControllerTrait: NewListControllerTrait(
|
|
c,
|
|
c.Contexts().ReflogCommits,
|
|
c.Contexts().ReflogCommits.GetSelected,
|
|
c.Contexts().ReflogCommits.GetSelectedItems,
|
|
),
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *ReflogCommitsController) Context() types.Context {
|
|
return self.context()
|
|
}
|
|
|
|
func (self *ReflogCommitsController) context() *context.ReflogCommitsContext {
|
|
return self.c.Contexts().ReflogCommits
|
|
}
|
|
|
|
func (self *ReflogCommitsController) GetFocusedMainViewDiffSource() types.FocusedMainViewDiffSource {
|
|
return self
|
|
}
|
|
|
|
// PlainDiff hands out the reflog entry's diff for the given files — the same diff its
|
|
// main view shows, only without the entry's message and stat above it.
|
|
func (self *ReflogCommitsController) PlainDiff(_ types.DiffPaneContext, paths []string) string {
|
|
commit := self.context().GetSelected()
|
|
if commit == nil {
|
|
return ""
|
|
}
|
|
return self.c.Helpers().Diff.PlainDiffBetweenRefs(commit.ParentRefName(), commit.RefName(), paths)
|
|
}
|
|
|
|
func (self *ReflogCommitsController) GetOnRenderToMain() func() {
|
|
return func() {
|
|
self.c.Helpers().Diff.WithDiffModeCheck(func() {
|
|
commit := self.context().GetSelected()
|
|
var task types.UpdateTask
|
|
if commit == nil {
|
|
task = types.NewRenderStringTask("No reflog history")
|
|
} else {
|
|
mode := self.c.Helpers().DiffLine.MainViewDiffMode()
|
|
cmdObj := self.c.Git().Commit.ShowCmdObj(commit.Hash(), self.c.Helpers().Diff.FilterPathsForCommit(commit), mode)
|
|
|
|
task = types.NewMainViewDiffTask(cmdObj.GetCmd(), mode)
|
|
}
|
|
|
|
self.c.RenderToMainViews(types.RefreshMainOpts{
|
|
Pair: self.c.MainViewPairs().Normal,
|
|
Main: &types.ViewUpdateOpts{
|
|
Title: "Reflog Entry",
|
|
Task: task,
|
|
},
|
|
})
|
|
})
|
|
}
|
|
}
|