mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
add reflog tab in commits panel
This commit is contained in:
@ -67,8 +67,8 @@ Default path for the config file: `~/.config/jesseduffield/lazygit/config.yml`
|
|||||||
pullFiles: 'p'
|
pullFiles: 'p'
|
||||||
refresh: 'R'
|
refresh: 'R'
|
||||||
createPatchOptionsMenu: '<c-p>'
|
createPatchOptionsMenu: '<c-p>'
|
||||||
nextBranchTab: ']'
|
nextTab: ']'
|
||||||
prevBranchTab: '['
|
prevTab: '['
|
||||||
status:
|
status:
|
||||||
checkForUpdate: 'u'
|
checkForUpdate: 'u'
|
||||||
recentRepos: '<enter>'
|
recentRepos: '<enter>'
|
||||||
|
@ -44,6 +44,8 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
|
|||||||
shaColor = green
|
shaColor = green
|
||||||
case "rebasing":
|
case "rebasing":
|
||||||
shaColor = blue
|
shaColor = blue
|
||||||
|
case "reflog":
|
||||||
|
shaColor = blue
|
||||||
case "selected":
|
case "selected":
|
||||||
shaColor = magenta
|
shaColor = magenta
|
||||||
default:
|
default:
|
||||||
|
@ -1113,3 +1113,28 @@ func (c *GitCommand) PushTag(remoteName string, tagName string) error {
|
|||||||
func (c *GitCommand) FetchRemote(remoteName string) error {
|
func (c *GitCommand) FetchRemote(remoteName string) error {
|
||||||
return c.OSCommand.RunCommand("git fetch %s", remoteName)
|
return c.OSCommand.RunCommand("git fetch %s", remoteName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GitCommand) GetReflogCommits() ([]*Commit, error) {
|
||||||
|
output, err := c.OSCommand.RunCommandWithOutput("git reflog")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(strings.TrimSpace(output), "\n")
|
||||||
|
commits := make([]*Commit, len(lines))
|
||||||
|
re := regexp.MustCompile(`(\w+).*HEAD@\{\d+\}: (.*)`)
|
||||||
|
for i, line := range lines {
|
||||||
|
match := re.FindStringSubmatch(line)
|
||||||
|
if len(match) == 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
commits[i] = &Commit{
|
||||||
|
Sha: match[1],
|
||||||
|
Name: match[2],
|
||||||
|
Status: "reflog",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return commits, nil
|
||||||
|
}
|
||||||
|
@ -300,8 +300,8 @@ keybinding:
|
|||||||
pullFiles: 'p'
|
pullFiles: 'p'
|
||||||
refresh: 'R'
|
refresh: 'R'
|
||||||
createPatchOptionsMenu: '<c-p>'
|
createPatchOptionsMenu: '<c-p>'
|
||||||
nextBranchTab: ']'
|
nextTab: ']'
|
||||||
prevBranchTab: '['
|
prevTab: '['
|
||||||
status:
|
status:
|
||||||
checkForUpdate: 'u'
|
checkForUpdate: 'u'
|
||||||
recentRepos: '<enter>'
|
recentRepos: '<enter>'
|
||||||
|
@ -111,9 +111,11 @@ func (gui *Gui) renderLocalBranchesWithSelection() error {
|
|||||||
if err := gui.renderListPanel(branchesView, gui.State.Branches); err != nil {
|
if err := gui.renderListPanel(branchesView, gui.State.Branches); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if gui.g.CurrentView() == branchesView && branchesView.Context == "local-branches" {
|
||||||
if err := gui.handleBranchSelect(gui.g, branchesView); err != nil {
|
if err := gui.handleBranchSelect(gui.g, branchesView); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -74,21 +74,18 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
gui.State.Commits = commits
|
gui.State.Commits = commits
|
||||||
|
|
||||||
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
|
// doing this async because it shouldn't hold anything up
|
||||||
|
go func() {
|
||||||
isFocused := gui.g.CurrentView().Name() == "commits"
|
if err := gui.refreshReflogCommits(); err != nil {
|
||||||
list, err := utils.RenderList(gui.State.Commits, isFocused)
|
_ = gui.createErrorPanel(gui.g, err.Error())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
v := gui.getCommitsView()
|
|
||||||
v.Clear()
|
|
||||||
fmt.Fprint(v, list)
|
|
||||||
|
|
||||||
gui.refreshStatus(g)
|
gui.refreshStatus(g)
|
||||||
if g.CurrentView() == v {
|
if gui.getCommitsView().Context == "branch-commits" {
|
||||||
gui.handleCommitSelect(g, v)
|
if err := gui.renderBranchCommitsWithSelection(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") {
|
if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") {
|
||||||
return gui.refreshCommitFilesView()
|
return gui.refreshCommitFilesView()
|
||||||
@ -622,3 +619,60 @@ func (gui *Gui) handleCheckoutCommit(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.handleCheckoutRef(commit.Sha)
|
return gui.handleCheckoutRef(commit.Sha)
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) renderBranchCommitsWithSelection() error {
|
||||||
|
commitsView := gui.getCommitsView()
|
||||||
|
|
||||||
|
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
|
||||||
|
if err := gui.renderListPanel(commitsView, gui.State.Commits); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" {
|
||||||
|
if err := gui.handleCommitSelect(gui.g, commitsView); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) onCommitsTabClick(tabIndex int) error {
|
||||||
|
contexts := []string{"branch-commits", "reflog-commits"}
|
||||||
|
commitsView := gui.getCommitsView()
|
||||||
|
commitsView.TabIndex = tabIndex
|
||||||
|
|
||||||
|
return gui.switchCommitsPanelContext(contexts[tabIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) switchCommitsPanelContext(context string) error {
|
||||||
|
commitsView := gui.getCommitsView()
|
||||||
|
commitsView.Context = context
|
||||||
|
|
||||||
|
contextTabIndexMap := map[string]int{
|
||||||
|
"branch-commits": 0,
|
||||||
|
"reflog-commits": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
commitsView.TabIndex = contextTabIndexMap[context]
|
||||||
|
|
||||||
|
switch context {
|
||||||
|
case "branch-commits":
|
||||||
|
return gui.renderBranchCommitsWithSelection()
|
||||||
|
case "reflog-commits":
|
||||||
|
return gui.renderReflogCommitsWithSelection()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleNextCommitsTab(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return gui.onCommitsTabClick(
|
||||||
|
utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handlePrevCommitsTab(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return gui.onCommitsTabClick(
|
||||||
|
utils.ModuloWithWrap(v.TabIndex-1, len(v.Tabs)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -130,6 +130,10 @@ type commitPanelState struct {
|
|||||||
SpecificDiffMode bool
|
SpecificDiffMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type reflogCommitPanelState struct {
|
||||||
|
SelectedLine int
|
||||||
|
}
|
||||||
|
|
||||||
type stashPanelState struct {
|
type stashPanelState struct {
|
||||||
SelectedLine int
|
SelectedLine int
|
||||||
}
|
}
|
||||||
@ -155,6 +159,7 @@ type panelStates struct {
|
|||||||
RemoteBranches *remoteBranchesState
|
RemoteBranches *remoteBranchesState
|
||||||
Tags *tagsPanelState
|
Tags *tagsPanelState
|
||||||
Commits *commitPanelState
|
Commits *commitPanelState
|
||||||
|
ReflogCommits *reflogCommitPanelState
|
||||||
Stash *stashPanelState
|
Stash *stashPanelState
|
||||||
Menu *menuPanelState
|
Menu *menuPanelState
|
||||||
LineByLine *lineByLinePanelState
|
LineByLine *lineByLinePanelState
|
||||||
@ -169,6 +174,7 @@ type guiState struct {
|
|||||||
Commits []*commands.Commit
|
Commits []*commands.Commit
|
||||||
StashEntries []*commands.StashEntry
|
StashEntries []*commands.StashEntry
|
||||||
CommitFiles []*commands.CommitFile
|
CommitFiles []*commands.CommitFile
|
||||||
|
ReflogCommits []*commands.Commit
|
||||||
DiffEntries []*commands.Commit
|
DiffEntries []*commands.Commit
|
||||||
Remotes []*commands.Remote
|
Remotes []*commands.Remote
|
||||||
RemoteBranches []*commands.RemoteBranch
|
RemoteBranches []*commands.RemoteBranch
|
||||||
@ -207,6 +213,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
|
|||||||
RemoteBranches: &remoteBranchesState{SelectedLine: -1},
|
RemoteBranches: &remoteBranchesState{SelectedLine: -1},
|
||||||
Tags: &tagsPanelState{SelectedLine: -1},
|
Tags: &tagsPanelState{SelectedLine: -1},
|
||||||
Commits: &commitPanelState{SelectedLine: -1},
|
Commits: &commitPanelState{SelectedLine: -1},
|
||||||
|
ReflogCommits: &reflogCommitPanelState{SelectedLine: 0}, // TODO: might need to make -1
|
||||||
CommitFiles: &commitFilesPanelState{SelectedLine: -1},
|
CommitFiles: &commitFilesPanelState{SelectedLine: -1},
|
||||||
Stash: &stashPanelState{SelectedLine: -1},
|
Stash: &stashPanelState{SelectedLine: -1},
|
||||||
Menu: &menuPanelState{SelectedLine: 0},
|
Menu: &menuPanelState{SelectedLine: 0},
|
||||||
@ -523,6 +530,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
||||||
|
commitsView.Tabs = []string{"Commits", "Reflog"}
|
||||||
commitsView.FgColor = textColor
|
commitsView.FgColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,7 +633,8 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
{view: branchesView, context: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches)},
|
{view: branchesView, context: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches)},
|
||||||
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)},
|
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)},
|
||||||
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes)},
|
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes)},
|
||||||
{view: commitsView, context: "", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
|
{view: commitsView, context: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
|
||||||
|
{view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.ReflogCommits)},
|
||||||
{view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
|
{view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,6 +666,7 @@ func (gui *Gui) onInitialViewsCreation() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui.getBranchesView().Context = "local-branches"
|
gui.getBranchesView().Context = "local-branches"
|
||||||
|
gui.getCommitsView().Context = "branch-commits"
|
||||||
|
|
||||||
return gui.loadNewRepo()
|
return gui.loadNewRepo()
|
||||||
}
|
}
|
||||||
|
@ -571,13 +571,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "branches",
|
ViewName: "branches",
|
||||||
Key: gui.getKey("universal.nextBranchTab"),
|
Key: gui.getKey("universal.nextTab"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleNextBranchesTab,
|
Handler: gui.handleNextBranchesTab,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "branches",
|
ViewName: "branches",
|
||||||
Key: gui.getKey("universal.prevBranchTab"),
|
Key: gui.getKey("universal.prevTab"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handlePrevBranchesTab,
|
Handler: gui.handlePrevBranchesTab,
|
||||||
},
|
},
|
||||||
@ -599,6 +599,19 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Key: gui.getKey("universal.nextTab"),
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleNextCommitsTab,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ViewName: "commits",
|
||||||
|
Key: gui.getKey("universal.prevTab"),
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handlePrevCommitsTab,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.squashDown"),
|
Key: gui.getKey("commits.squashDown"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitSquashDown,
|
Handler: gui.handleCommitSquashDown,
|
||||||
@ -606,6 +619,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.renameCommit"),
|
Key: gui.getKey("commits.renameCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleRenameCommit,
|
Handler: gui.handleRenameCommit,
|
||||||
@ -613,6 +627,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.renameCommitWithEditor"),
|
Key: gui.getKey("commits.renameCommitWithEditor"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleRenameCommitEditor,
|
Handler: gui.handleRenameCommitEditor,
|
||||||
@ -620,6 +635,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.viewResetOptions"),
|
Key: gui.getKey("commits.viewResetOptions"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCreateCommitResetMenu,
|
Handler: gui.handleCreateCommitResetMenu,
|
||||||
@ -627,6 +643,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.markCommitAsFixup"),
|
Key: gui.getKey("commits.markCommitAsFixup"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitFixup,
|
Handler: gui.handleCommitFixup,
|
||||||
@ -634,6 +651,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.createFixupCommit"),
|
Key: gui.getKey("commits.createFixupCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCreateFixupCommit,
|
Handler: gui.handleCreateFixupCommit,
|
||||||
@ -641,6 +659,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.squashAboveCommits"),
|
Key: gui.getKey("commits.squashAboveCommits"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleSquashAllAboveFixupCommits,
|
Handler: gui.handleSquashAllAboveFixupCommits,
|
||||||
@ -648,6 +667,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("universal.remove"),
|
Key: gui.getKey("universal.remove"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitDelete,
|
Handler: gui.handleCommitDelete,
|
||||||
@ -655,6 +675,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.moveDownCommit"),
|
Key: gui.getKey("commits.moveDownCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitMoveDown,
|
Handler: gui.handleCommitMoveDown,
|
||||||
@ -662,6 +683,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.moveUpCommit"),
|
Key: gui.getKey("commits.moveUpCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitMoveUp,
|
Handler: gui.handleCommitMoveUp,
|
||||||
@ -669,6 +691,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("universal.edit"),
|
Key: gui.getKey("universal.edit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitEdit,
|
Handler: gui.handleCommitEdit,
|
||||||
@ -676,6 +699,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.amendToCommit"),
|
Key: gui.getKey("commits.amendToCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitAmendTo,
|
Handler: gui.handleCommitAmendTo,
|
||||||
@ -683,6 +707,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.pickCommit"),
|
Key: gui.getKey("commits.pickCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitPick,
|
Handler: gui.handleCommitPick,
|
||||||
@ -690,6 +715,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.revertCommit"),
|
Key: gui.getKey("commits.revertCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitRevert,
|
Handler: gui.handleCommitRevert,
|
||||||
@ -697,6 +723,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.cherryPickCopy"),
|
Key: gui.getKey("commits.cherryPickCopy"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCopyCommit,
|
Handler: gui.handleCopyCommit,
|
||||||
@ -704,6 +731,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.cherryPickCopyRange"),
|
Key: gui.getKey("commits.cherryPickCopyRange"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCopyCommitRange,
|
Handler: gui.handleCopyCommitRange,
|
||||||
@ -711,6 +739,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.pasteCommits"),
|
Key: gui.getKey("commits.pasteCommits"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.HandlePasteCommits,
|
Handler: gui.HandlePasteCommits,
|
||||||
@ -718,6 +747,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("universal.goInto"),
|
Key: gui.getKey("universal.goInto"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleSwitchToCommitFilesPanel,
|
Handler: gui.handleSwitchToCommitFilesPanel,
|
||||||
@ -725,6 +755,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.checkoutCommit"),
|
Key: gui.getKey("commits.checkoutCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCheckoutCommit,
|
Handler: gui.handleCheckoutCommit,
|
||||||
@ -732,6 +763,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.toggleDiffCommit"),
|
Key: gui.getKey("commits.toggleDiffCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleToggleDiffCommit,
|
Handler: gui.handleToggleDiffCommit,
|
||||||
@ -739,6 +771,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
|
Contexts: []string{"branch-commits"},
|
||||||
Key: gui.getKey("commits.tagCommit"),
|
Key: gui.getKey("commits.tagCommit"),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleTagCommit,
|
Handler: gui.handleTagCommit,
|
||||||
@ -1335,9 +1368,16 @@ func (gui *Gui) keybindings(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.SetTabClickBinding("branches", gui.onBranchesTabClick); err != nil {
|
tabClickBindings := map[string]func(int) error{
|
||||||
|
"branches": gui.onBranchesTabClick,
|
||||||
|
"commits": gui.onCommitsTabClick,
|
||||||
|
}
|
||||||
|
|
||||||
|
for viewName, binding := range tabClickBindings {
|
||||||
|
if err := g.SetTabClickBinding(viewName, binding); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -126,8 +126,10 @@ func (gui *Gui) getListViews() []*listView {
|
|||||||
gui: gui,
|
gui: gui,
|
||||||
rendersToMainView: true,
|
rendersToMainView: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
viewName: "commits",
|
viewName: "commits",
|
||||||
|
context: "branch-commits",
|
||||||
getItemsLength: func() int { return len(gui.State.Commits) },
|
getItemsLength: func() int { return len(gui.State.Commits) },
|
||||||
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine },
|
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine },
|
||||||
handleFocus: gui.handleCommitSelect,
|
handleFocus: gui.handleCommitSelect,
|
||||||
@ -136,6 +138,16 @@ func (gui *Gui) getListViews() []*listView {
|
|||||||
gui: gui,
|
gui: gui,
|
||||||
rendersToMainView: true,
|
rendersToMainView: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
viewName: "commits",
|
||||||
|
context: "reflog-commits",
|
||||||
|
getItemsLength: func() int { return len(gui.State.ReflogCommits) },
|
||||||
|
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
|
||||||
|
handleFocus: gui.handleReflogCommitSelect,
|
||||||
|
handleItemSelect: gui.handleReflogCommitSelect,
|
||||||
|
gui: gui,
|
||||||
|
rendersToMainView: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
viewName: "stash",
|
viewName: "stash",
|
||||||
getItemsLength: func() int { return len(gui.State.StashEntries) },
|
getItemsLength: func() int { return len(gui.State.StashEntries) },
|
||||||
|
76
pkg/gui/reflog_panel.go
Normal file
76
pkg/gui/reflog_panel.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package gui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
)
|
||||||
|
|
||||||
|
// list panel functions
|
||||||
|
|
||||||
|
func (gui *Gui) getSelectedReflogCommit() *commands.Commit {
|
||||||
|
selectedLine := gui.State.Panels.ReflogCommits.SelectedLine
|
||||||
|
if selectedLine == -1 || len(gui.State.ReflogCommits) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.State.ReflogCommits[selectedLine]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
if gui.popupPanelFocused() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.SplitMainPanel = false
|
||||||
|
|
||||||
|
if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.getMainView().Title = "Reflog Entry"
|
||||||
|
|
||||||
|
commit := gui.getSelectedReflogCommit()
|
||||||
|
if commit == nil {
|
||||||
|
return gui.renderString(g, "main", "No reflog history")
|
||||||
|
}
|
||||||
|
if err := gui.focusPoint(0, gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.ReflogCommits), v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
commitText, err := gui.GitCommand.Show(commit.Sha)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return gui.renderString(g, "main", commitText)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) refreshReflogCommits() error {
|
||||||
|
commits, err := gui.GitCommand.GetReflogCommits()
|
||||||
|
if err != nil {
|
||||||
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.ReflogCommits = commits
|
||||||
|
|
||||||
|
if gui.getCommitsView().Context == "reflog-commits" {
|
||||||
|
return gui.renderReflogCommitsWithSelection()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) renderReflogCommitsWithSelection() error {
|
||||||
|
commitsView := gui.getCommitsView()
|
||||||
|
|
||||||
|
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.ReflogCommits))
|
||||||
|
if err := gui.renderListPanel(commitsView, gui.State.ReflogCommits); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" {
|
||||||
|
if err := gui.handleReflogCommitSelect(gui.g, commitsView); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -67,9 +67,11 @@ func (gui *Gui) renderRemoteBranchesWithSelection() error {
|
|||||||
if err := gui.renderListPanel(branchesView, gui.State.RemoteBranches); err != nil {
|
if err := gui.renderListPanel(branchesView, gui.State.RemoteBranches); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if gui.g.CurrentView() == branchesView && branchesView.Context == "remote-branches" {
|
||||||
if err := gui.handleRemoteBranchSelect(gui.g, branchesView); err != nil {
|
if err := gui.handleRemoteBranchSelect(gui.g, branchesView); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -83,9 +83,11 @@ func (gui *Gui) renderRemotesWithSelection() error {
|
|||||||
if err := gui.renderListPanel(branchesView, gui.State.Remotes); err != nil {
|
if err := gui.renderListPanel(branchesView, gui.State.Remotes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if gui.g.CurrentView() == branchesView && branchesView.Context == "remotes" {
|
||||||
if err := gui.handleRemoteSelect(gui.g, branchesView); err != nil {
|
if err := gui.handleRemoteSelect(gui.g, branchesView); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,11 @@ func (gui *Gui) renderTagsWithSelection() error {
|
|||||||
if err := gui.renderListPanel(branchesView, gui.State.Tags); err != nil {
|
if err := gui.renderListPanel(branchesView, gui.State.Tags); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if gui.g.CurrentView() == branchesView && branchesView.Context == "tags" {
|
||||||
if err := gui.handleTagSelect(gui.g, branchesView); err != nil {
|
if err := gui.handleTagSelect(gui.g, branchesView); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user