mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
allowing commit files to be viewed in reflog as well
This commit is contained in:
parent
48f1adad49
commit
ddf25e14af
@ -39,10 +39,6 @@ func (gui *Gui) handleCommitFileSelect() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleSwitchToCommitsPanel(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
return gui.switchContext(gui.Contexts.BranchCommits.Context)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error {
|
||||||
file := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLineIdx]
|
file := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLineIdx]
|
||||||
|
|
||||||
@ -84,18 +80,13 @@ func (gui *Gui) refreshCommitFilesView() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
commit := gui.getSelectedCommit()
|
files, err := gui.GitCommand.GetCommitFiles(gui.State.Panels.CommitFiles.refName, gui.GitCommand.PatchManager)
|
||||||
if commit == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
files, err := gui.GitCommand.GetCommitFiles(commit.Sha, gui.GitCommand.PatchManager)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
gui.State.CommitFiles = files
|
gui.State.CommitFiles = files
|
||||||
|
|
||||||
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Files.Context)
|
return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
|
||||||
@ -213,7 +204,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
|
|||||||
return enterTheFile(selectedLineIdx)
|
return enterTheFile(selectedLineIdx)
|
||||||
},
|
},
|
||||||
handleClose: func() error {
|
handleClose: func() error {
|
||||||
return gui.switchContext(gui.Contexts.BranchCommits.Files.Context)
|
return gui.switchContext(gui.Contexts.CommitFiles.Context)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -499,12 +499,20 @@ func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleSwitchToCommitFilesPanel() error {
|
func (gui *Gui) handleViewCommitFiles() error {
|
||||||
|
commit := gui.getSelectedCommit()
|
||||||
|
if commit == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.Panels.CommitFiles.refName = commit.Sha
|
||||||
|
gui.Contexts.CommitFiles.Context.SetParentContext(gui.Contexts.BranchCommits.Context)
|
||||||
|
|
||||||
if err := gui.refreshCommitFilesView(); err != nil {
|
if err := gui.refreshCommitFilesView(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.switchContext(gui.Contexts.BranchCommits.Files.Context)
|
return gui.switchContext(gui.Contexts.CommitFiles.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
|
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
|
||||||
|
@ -43,6 +43,8 @@ type Context interface {
|
|||||||
GetViewName() string
|
GetViewName() string
|
||||||
GetKey() string
|
GetKey() string
|
||||||
GetSelectedItemId() string
|
GetSelectedItemId() string
|
||||||
|
SetParentContext(Context)
|
||||||
|
GetParentContext() Context
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicContext struct {
|
type BasicContext struct {
|
||||||
@ -54,6 +56,14 @@ type BasicContext struct {
|
|||||||
ViewName string
|
ViewName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c BasicContext) SetParentContext(Context) {
|
||||||
|
panic("can't set parent context on basic context")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c BasicContext) GetParentContext() Context {
|
||||||
|
panic("can't get parent context on basic context")
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: think about whether we need this on the Context interface or if it should just be on the ListContext struct
|
// TODO: think about whether we need this on the Context interface or if it should just be on the ListContext struct
|
||||||
func (c BasicContext) GetSelectedItemId() string {
|
func (c BasicContext) GetSelectedItemId() string {
|
||||||
return ""
|
return ""
|
||||||
@ -98,11 +108,6 @@ type RemotesContextNode struct {
|
|||||||
Branches SimpleContextNode
|
Branches SimpleContextNode
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitsContextNode struct {
|
|
||||||
Context Context
|
|
||||||
Files SimpleContextNode
|
|
||||||
}
|
|
||||||
|
|
||||||
type ContextTree struct {
|
type ContextTree struct {
|
||||||
Status SimpleContextNode
|
Status SimpleContextNode
|
||||||
Files SimpleContextNode
|
Files SimpleContextNode
|
||||||
@ -110,7 +115,8 @@ type ContextTree struct {
|
|||||||
Branches SimpleContextNode
|
Branches SimpleContextNode
|
||||||
Remotes RemotesContextNode
|
Remotes RemotesContextNode
|
||||||
Tags SimpleContextNode
|
Tags SimpleContextNode
|
||||||
BranchCommits CommitsContextNode
|
BranchCommits SimpleContextNode
|
||||||
|
CommitFiles SimpleContextNode
|
||||||
ReflogCommits SimpleContextNode
|
ReflogCommits SimpleContextNode
|
||||||
Stash SimpleContextNode
|
Stash SimpleContextNode
|
||||||
Normal SimpleContextNode
|
Normal SimpleContextNode
|
||||||
@ -132,7 +138,7 @@ func (gui *Gui) allContexts() []Context {
|
|||||||
gui.Contexts.Remotes.Branches.Context,
|
gui.Contexts.Remotes.Branches.Context,
|
||||||
gui.Contexts.Tags.Context,
|
gui.Contexts.Tags.Context,
|
||||||
gui.Contexts.BranchCommits.Context,
|
gui.Contexts.BranchCommits.Context,
|
||||||
gui.Contexts.BranchCommits.Files.Context,
|
gui.Contexts.CommitFiles.Context,
|
||||||
gui.Contexts.ReflogCommits.Context,
|
gui.Contexts.ReflogCommits.Context,
|
||||||
gui.Contexts.Stash.Context,
|
gui.Contexts.Stash.Context,
|
||||||
gui.Contexts.Menu.Context,
|
gui.Contexts.Menu.Context,
|
||||||
@ -168,11 +174,11 @@ func (gui *Gui) contextTree() ContextTree {
|
|||||||
Context: gui.remoteBranchesListContext(),
|
Context: gui.remoteBranchesListContext(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
BranchCommits: CommitsContextNode{
|
BranchCommits: SimpleContextNode{
|
||||||
Context: gui.branchCommitsListContext(),
|
Context: gui.branchCommitsListContext(),
|
||||||
Files: SimpleContextNode{
|
|
||||||
Context: gui.commitFilesListContext(),
|
|
||||||
},
|
},
|
||||||
|
CommitFiles: SimpleContextNode{
|
||||||
|
Context: gui.commitFilesListContext(),
|
||||||
},
|
},
|
||||||
ReflogCommits: SimpleContextNode{
|
ReflogCommits: SimpleContextNode{
|
||||||
Context: gui.reflogCommitsListContext(),
|
Context: gui.reflogCommitsListContext(),
|
||||||
@ -271,7 +277,7 @@ func (gui *Gui) initialViewContextMap() map[string]Context {
|
|||||||
"files": gui.Contexts.Files.Context,
|
"files": gui.Contexts.Files.Context,
|
||||||
"branches": gui.Contexts.Branches.Context,
|
"branches": gui.Contexts.Branches.Context,
|
||||||
"commits": gui.Contexts.BranchCommits.Context,
|
"commits": gui.Contexts.BranchCommits.Context,
|
||||||
"commitFiles": gui.Contexts.BranchCommits.Files.Context,
|
"commitFiles": gui.Contexts.CommitFiles.Context,
|
||||||
"stash": gui.Contexts.Stash.Context,
|
"stash": gui.Contexts.Stash.Context,
|
||||||
"menu": gui.Contexts.Menu.Context,
|
"menu": gui.Contexts.Menu.Context,
|
||||||
"confirmation": gui.Contexts.Confirmation.Context,
|
"confirmation": gui.Contexts.Confirmation.Context,
|
||||||
@ -474,12 +480,22 @@ func (gui *Gui) renderContextStack() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) currentContextKey() string {
|
func (gui *Gui) currentContextKey() string {
|
||||||
// on startup the stack can be empty so we'll return an empty string in that case
|
currentContext := gui.currentContext()
|
||||||
if len(gui.State.ContextStack) == 0 {
|
|
||||||
|
if currentContext == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.State.ContextStack[len(gui.State.ContextStack)-1].GetKey()
|
return currentContext.GetKey()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) currentContext() Context {
|
||||||
|
// on startup the stack can be empty so we'll return an empty string in that case
|
||||||
|
if len(gui.State.ContextStack) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.State.ContextStack[len(gui.State.ContextStack)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setInitialViewContexts() {
|
func (gui *Gui) setInitialViewContexts() {
|
||||||
|
@ -184,6 +184,10 @@ type menuPanelState struct {
|
|||||||
|
|
||||||
type commitFilesPanelState struct {
|
type commitFilesPanelState struct {
|
||||||
listPanelState
|
listPanelState
|
||||||
|
|
||||||
|
// this is the SHA of the commit or the stash index of the stash.
|
||||||
|
// Not sure if ref is actually the right word here
|
||||||
|
refName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type panelStates struct {
|
type panelStates struct {
|
||||||
@ -291,7 +295,7 @@ func (gui *Gui) resetState() {
|
|||||||
Tags: &tagsPanelState{listPanelState{SelectedLineIdx: -1}},
|
Tags: &tagsPanelState{listPanelState{SelectedLineIdx: -1}},
|
||||||
Commits: &commitPanelState{listPanelState: listPanelState{SelectedLineIdx: -1}, LimitCommits: true},
|
Commits: &commitPanelState{listPanelState: listPanelState{SelectedLineIdx: -1}, LimitCommits: true},
|
||||||
ReflogCommits: &reflogCommitPanelState{listPanelState{SelectedLineIdx: 0}}, // TODO: might need to make -1
|
ReflogCommits: &reflogCommitPanelState{listPanelState{SelectedLineIdx: 0}}, // TODO: might need to make -1
|
||||||
CommitFiles: &commitFilesPanelState{listPanelState{SelectedLineIdx: -1}},
|
CommitFiles: &commitFilesPanelState{listPanelState: listPanelState{SelectedLineIdx: -1}, refName: ""},
|
||||||
Stash: &stashPanelState{listPanelState{SelectedLineIdx: -1}},
|
Stash: &stashPanelState{listPanelState{SelectedLineIdx: -1}},
|
||||||
Menu: &menuPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, OnPress: nil},
|
Menu: &menuPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, OnPress: nil},
|
||||||
Merging: &mergingPanelState{
|
Merging: &mergingPanelState{
|
||||||
|
@ -765,7 +765,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
|
Contexts: []string{BRANCH_COMMITS_CONTEXT_KEY},
|
||||||
Key: gui.getKey("universal.goInto"),
|
Key: gui.getKey("universal.goInto"),
|
||||||
Handler: gui.wrappedHandler(gui.handleSwitchToCommitFilesPanel),
|
Handler: gui.wrappedHandler(gui.handleViewCommitFiles),
|
||||||
Description: gui.Tr.SLocalize("viewCommitFiles"),
|
Description: gui.Tr.SLocalize("viewCommitFiles"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -797,6 +797,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.handleResetCherryPick,
|
Handler: gui.handleResetCherryPick,
|
||||||
Description: gui.Tr.SLocalize("resetCherryPick"),
|
Description: gui.Tr.SLocalize("resetCherryPick"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ViewName: "commits",
|
||||||
|
Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY},
|
||||||
|
Key: gui.getKey("universal.goInto"),
|
||||||
|
Handler: gui.wrappedHandler(gui.handleViewReflogCommitFiles),
|
||||||
|
Description: gui.Tr.SLocalize("viewCommitFiles"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY},
|
Contexts: []string{REFLOG_COMMITS_CONTEXT_KEY},
|
||||||
@ -865,12 +872,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleInfoClick,
|
Handler: gui.handleInfoClick,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ViewName: "commitFiles",
|
|
||||||
Key: gui.getKey("universal.return"),
|
|
||||||
Handler: gui.handleSwitchToCommitsPanel,
|
|
||||||
Description: gui.Tr.SLocalize("goBack"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
ViewName: "commitFiles",
|
ViewName: "commitFiles",
|
||||||
Key: gui.getKey("commitFiles.checkoutCommitFile"),
|
Key: gui.getKey("commitFiles.checkoutCommitFile"),
|
||||||
|
@ -19,12 +19,21 @@ type ListContext struct {
|
|||||||
Gui *Gui
|
Gui *Gui
|
||||||
RendersToMainView bool
|
RendersToMainView bool
|
||||||
Kind int
|
Kind int
|
||||||
|
ParentContext Context
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListItem interface {
|
type ListItem interface {
|
||||||
ID() string
|
ID() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (lc *ListContext) SetParentContext(c Context) {
|
||||||
|
lc.ParentContext = c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lc *ListContext) GetParentContext() Context {
|
||||||
|
return lc.ParentContext
|
||||||
|
}
|
||||||
|
|
||||||
func (lc *ListContext) GetSelectedItem() ListItem {
|
func (lc *ListContext) GetSelectedItem() ListItem {
|
||||||
items := lc.GetItems()
|
items := lc.GetItems()
|
||||||
|
|
||||||
@ -317,7 +326,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
|
|||||||
GetItemsLength: func() int { return len(gui.State.Commits) },
|
GetItemsLength: func() int { return len(gui.State.Commits) },
|
||||||
GetPanelState: func() IListPanelState { return gui.State.Panels.Commits },
|
GetPanelState: func() IListPanelState { return gui.State.Panels.Commits },
|
||||||
OnFocus: gui.handleCommitSelect,
|
OnFocus: gui.handleCommitSelect,
|
||||||
OnClickSelectedItem: gui.handleSwitchToCommitFilesPanel,
|
OnClickSelectedItem: gui.handleViewCommitFiles,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
|
@ -82,7 +82,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error {
|
|||||||
gui.GitCommand.PatchManager.Reset()
|
gui.GitCommand.PatchManager.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.switchContext(gui.Contexts.BranchCommits.Files.Context)
|
return gui.switchContext(gui.Contexts.CommitFiles.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshSecondaryPatchPanel() error {
|
func (gui *Gui) refreshSecondaryPatchPanel() error {
|
||||||
|
@ -42,6 +42,12 @@ func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.exitFilterMode()
|
return gui.exitFilterMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentContext := gui.currentContext()
|
||||||
|
if currentContext != nil && currentContext.GetParentContext() != nil {
|
||||||
|
// TODO: think about whether this should be marked as a return rather than adding to the stack
|
||||||
|
gui.switchContext(currentContext.GetParentContext())
|
||||||
|
}
|
||||||
|
|
||||||
if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
|
if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
|
||||||
return gui.handleQuit()
|
return gui.handleQuit()
|
||||||
}
|
}
|
||||||
|
@ -112,3 +112,19 @@ func (gui *Gui) handleCreateReflogResetMenu(g *gocui.Gui, v *gocui.View) error {
|
|||||||
|
|
||||||
return gui.createResetMenu(commit.Sha)
|
return gui.createResetMenu(commit.Sha)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleViewReflogCommitFiles() error {
|
||||||
|
commit := gui.getSelectedReflogCommit()
|
||||||
|
if commit == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.Panels.CommitFiles.refName = commit.Sha
|
||||||
|
gui.Contexts.CommitFiles.Context.SetParentContext(gui.Contexts.ReflogCommits.Context)
|
||||||
|
|
||||||
|
if err := gui.refreshCommitFilesView(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.switchContext(gui.Contexts.CommitFiles.Context)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user