mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-13 11:50:28 +02:00
Add feature of display committed file list #383
This commit is contained in:
parent
1b6e46973e
commit
06fe726ee7
13
pkg/commands/commit_file.go
Normal file
13
pkg/commands/commit_file.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
// CommitFile : A git commit file
|
||||||
|
type CommitFile struct {
|
||||||
|
Sha string
|
||||||
|
Name string
|
||||||
|
DisplayString string
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDisplayStrings is a function.
|
||||||
|
func (f *CommitFile) GetDisplayStrings() []string {
|
||||||
|
return []string{f.DisplayString}
|
||||||
|
}
|
@ -796,3 +796,15 @@ func (c *GitCommand) CherryPickCommits(commits []*Commit) error {
|
|||||||
|
|
||||||
return c.OSCommand.RunPreparedCommand(cmd)
|
return c.OSCommand.RunPreparedCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommitFiles get the specified commit files
|
||||||
|
func (c *GitCommand) CommitFiles(commitID string) (string, error) {
|
||||||
|
cmd := fmt.Sprintf("git show --pretty= --name-only %s", commitID)
|
||||||
|
return c.OSCommand.RunCommandWithOutput(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowCommitFile get the diff of specified commit file
|
||||||
|
func (c *GitCommand) ShowCommitFile(commitID, file string) (string, error) {
|
||||||
|
cmd := fmt.Sprintf("git show --color %s -- %s", commitID, file)
|
||||||
|
return c.OSCommand.RunCommandWithOutput(cmd)
|
||||||
|
}
|
||||||
|
53
pkg/gui/commit_files_panel.go
Normal file
53
pkg/gui/commit_files_panel.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package gui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (gui *Gui) getSelectedCommitFile(g *gocui.Gui) *commands.CommitFile {
|
||||||
|
selectedLine := gui.State.Panels.CommitFiles.SelectedLine
|
||||||
|
if selectedLine == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.State.CommitFiles[selectedLine]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
commitFile := gui.getSelectedCommitFile(g)
|
||||||
|
if commitFile == nil {
|
||||||
|
return gui.renderString(g, "commit files", gui.Tr.SLocalize("NoCommiteFiles"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gui.focusPoint(0, gui.State.Panels.CommitFiles.SelectedLine, v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
commitText, err := gui.GitCommand.ShowCommitFile(commitFile.Sha, commitFile.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return gui.renderString(g, "main", commitText)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleCommitFilesNextLine(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
panelState := gui.State.Panels.CommitFiles
|
||||||
|
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.CommitFiles), false)
|
||||||
|
|
||||||
|
return gui.handleCommitFileSelect(gui.g, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleCommitFilesPrevLine(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
panelState := gui.State.Panels.CommitFiles
|
||||||
|
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.CommitFiles), true)
|
||||||
|
|
||||||
|
return gui.handleCommitFileSelect(gui.g, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleSwitchToCommitsPanel(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
commitsView, err := g.View("commits")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return gui.switchFocus(g, v, commitsView)
|
||||||
|
}
|
@ -3,6 +3,7 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
||||||
@ -437,3 +438,38 @@ func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
|
|||||||
})
|
})
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleSwitchToCommitFilesPanel(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
commit := gui.getSelectedCommit(g)
|
||||||
|
if commit == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
commitfileView, err := g.View("commit files")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := gui.GitCommand.CommitFiles(commit.Sha)
|
||||||
|
if err != nil {
|
||||||
|
return gui.createErrorPanel(g, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.Panels.CommitFiles = &commitFilesPanelState{SelectedLine: 0}
|
||||||
|
gui.State.CommitFiles = make([]*commands.CommitFile, 0)
|
||||||
|
|
||||||
|
if files == "" {
|
||||||
|
gui.State.Panels.CommitFiles.SelectedLine = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range strings.Split(strings.TrimRight(files, "\n"), "\n") {
|
||||||
|
gui.State.CommitFiles = append(gui.State.CommitFiles, &commands.CommitFile{
|
||||||
|
Sha: commit.Sha,
|
||||||
|
Name: file,
|
||||||
|
DisplayString: file,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.renderString(g, "commit files", files)
|
||||||
|
return gui.switchFocus(g, v, commitfileView)
|
||||||
|
}
|
||||||
|
@ -114,14 +114,19 @@ type menuPanelState struct {
|
|||||||
SelectedLine int
|
SelectedLine int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type commitFilesPanelState struct {
|
||||||
|
SelectedLine int
|
||||||
|
}
|
||||||
|
|
||||||
type panelStates struct {
|
type panelStates struct {
|
||||||
Files *filePanelState
|
Files *filePanelState
|
||||||
Branches *branchPanelState
|
Branches *branchPanelState
|
||||||
Commits *commitPanelState
|
Commits *commitPanelState
|
||||||
Stash *stashPanelState
|
Stash *stashPanelState
|
||||||
Menu *menuPanelState
|
Menu *menuPanelState
|
||||||
Staging *stagingPanelState
|
Staging *stagingPanelState
|
||||||
Merging *mergingPanelState
|
Merging *mergingPanelState
|
||||||
|
CommitFiles *commitFilesPanelState
|
||||||
}
|
}
|
||||||
|
|
||||||
type guiState struct {
|
type guiState struct {
|
||||||
@ -129,6 +134,7 @@ type guiState struct {
|
|||||||
Branches []*commands.Branch
|
Branches []*commands.Branch
|
||||||
Commits []*commands.Commit
|
Commits []*commands.Commit
|
||||||
StashEntries []*commands.StashEntry
|
StashEntries []*commands.StashEntry
|
||||||
|
CommitFiles []*commands.CommitFile
|
||||||
PreviousView string
|
PreviousView string
|
||||||
Platform commands.Platform
|
Platform commands.Platform
|
||||||
Updating bool
|
Updating bool
|
||||||
@ -352,6 +358,14 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
branchesView.FgColor = gocui.ColorWhite
|
branchesView.FgColor = gocui.ColorWhite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, err := g.SetView("commit files", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM); err != nil {
|
||||||
|
if err.Error() != "unknown view" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
v.Title = gui.Tr.SLocalize("CommitFiles")
|
||||||
|
v.FgColor = gocui.ColorWhite
|
||||||
|
}
|
||||||
|
|
||||||
commitsView, err := g.SetView("commits", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM)
|
commitsView, err := g.SetView("commits", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() != "unknown view" {
|
if err.Error() != "unknown view" {
|
||||||
|
@ -388,6 +388,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.HandlePasteCommits,
|
Handler: gui.HandlePasteCommits,
|
||||||
Description: gui.Tr.SLocalize("pasteCommits"),
|
Description: gui.Tr.SLocalize("pasteCommits"),
|
||||||
|
}, {
|
||||||
|
ViewName: "commits",
|
||||||
|
Key: gocui.KeyEnter,
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleSwitchToCommitFilesPanel,
|
||||||
|
Description: gui.Tr.SLocalize("CommitFiles"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "stash",
|
ViewName: "stash",
|
||||||
Key: gocui.KeySpace,
|
Key: gocui.KeySpace,
|
||||||
@ -441,6 +447,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Key: gocui.MouseLeft,
|
Key: gocui.MouseLeft,
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleDonate,
|
Handler: gui.handleDonate,
|
||||||
|
}, {
|
||||||
|
ViewName: "commit files",
|
||||||
|
Key: gocui.KeyEsc,
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleSwitchToCommitsPanel,
|
||||||
|
Description: gui.Tr.SLocalize("CommitsTitle"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,12 +471,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
nextLine func(*gocui.Gui, *gocui.View) error
|
nextLine func(*gocui.Gui, *gocui.View) error
|
||||||
focus func(*gocui.Gui, *gocui.View) error
|
focus func(*gocui.Gui, *gocui.View) error
|
||||||
}{
|
}{
|
||||||
"menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuSelect},
|
"menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuSelect},
|
||||||
"files": {prevLine: gui.handleFilesPrevLine, nextLine: gui.handleFilesNextLine, focus: gui.handleFilesFocus},
|
"files": {prevLine: gui.handleFilesPrevLine, nextLine: gui.handleFilesNextLine, focus: gui.handleFilesFocus},
|
||||||
"branches": {prevLine: gui.handleBranchesPrevLine, nextLine: gui.handleBranchesNextLine, focus: gui.handleBranchSelect},
|
"branches": {prevLine: gui.handleBranchesPrevLine, nextLine: gui.handleBranchesNextLine, focus: gui.handleBranchSelect},
|
||||||
"commits": {prevLine: gui.handleCommitsPrevLine, nextLine: gui.handleCommitsNextLine, focus: gui.handleCommitSelect},
|
"commits": {prevLine: gui.handleCommitsPrevLine, nextLine: gui.handleCommitsNextLine, focus: gui.handleCommitSelect},
|
||||||
"stash": {prevLine: gui.handleStashPrevLine, nextLine: gui.handleStashNextLine, focus: gui.handleStashEntrySelect},
|
"stash": {prevLine: gui.handleStashPrevLine, nextLine: gui.handleStashNextLine, focus: gui.handleStashEntrySelect},
|
||||||
"status": {focus: gui.handleStatusSelect},
|
"status": {focus: gui.handleStatusSelect},
|
||||||
|
"commit files": {prevLine: gui.handleCommitFilesPrevLine, nextLine: gui.handleCommitFilesNextLine},
|
||||||
}
|
}
|
||||||
|
|
||||||
for viewName, functions := range listPanelMap {
|
for viewName, functions := range listPanelMap {
|
||||||
|
@ -95,6 +95,8 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.handleBranchSelect(g, v)
|
return gui.handleBranchSelect(g, v)
|
||||||
case "commits":
|
case "commits":
|
||||||
return gui.handleCommitSelect(g, v)
|
return gui.handleCommitSelect(g, v)
|
||||||
|
case "commit files":
|
||||||
|
return gui.handleCommitFileSelect(g, v)
|
||||||
case "stash":
|
case "stash":
|
||||||
return gui.handleStashEntrySelect(g, v)
|
return gui.handleStashEntrySelect(g, v)
|
||||||
case "confirmation":
|
case "confirmation":
|
||||||
|
@ -643,6 +643,12 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CherryPickingStatus",
|
ID: "CherryPickingStatus",
|
||||||
Other: "cherry-picking",
|
Other: "cherry-picking",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitFiles",
|
||||||
|
Other: "Commit files",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "NoCommiteFiles",
|
||||||
|
Other: "No files for this commit",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -666,6 +666,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CherryPickingStatus",
|
ID: "CherryPickingStatus",
|
||||||
Other: "cherry-picking",
|
Other: "cherry-picking",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitFiles",
|
||||||
|
Other: "Commit files",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "NoCommiteFiles",
|
||||||
|
Other: "No files for this commit",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -626,6 +626,12 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CherryPickingStatus",
|
ID: "CherryPickingStatus",
|
||||||
Other: "cherry-picking",
|
Other: "cherry-picking",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "CommitFiles",
|
||||||
|
Other: "Commit files",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "NoCommiteFiles",
|
||||||
|
Other: "No files for this commit",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user