mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
better handling of there being no commit files
This commit is contained in:
parent
2915134007
commit
4fb52ce2ab
@ -1066,6 +1066,9 @@ func (c *GitCommand) GetCommitFilesFromFilenames(filenames string, parent string
|
|||||||
|
|
||||||
for _, line := range strings.Split(strings.TrimRight(filenames, "\n"), "\n") {
|
for _, line := range strings.Split(strings.TrimRight(filenames, "\n"), "\n") {
|
||||||
// typical result looks like 'A my_file' meaning my_file was added
|
// typical result looks like 'A my_file' meaning my_file was added
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
changeStatus := line[0:1]
|
changeStatus := line[0:1]
|
||||||
name := line[2:]
|
name := line[2:]
|
||||||
status := patch.UNSELECTED
|
status := patch.UNSELECTED
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
|
func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
|
||||||
selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx
|
selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx
|
||||||
if selectedLine == -1 {
|
if selectedLine == -1 || selectedLine > len(gui.State.CommitFiles)-1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,8 +19,6 @@ func (gui *Gui) handleCommitFileSelect() error {
|
|||||||
|
|
||||||
commitFile := gui.getSelectedCommitFile()
|
commitFile := gui.getSelectedCommitFile()
|
||||||
if commitFile == nil {
|
if commitFile == nil {
|
||||||
// TODO: consider making it so that we can also render strings to our own view through some common interface, or just render this to the main view for consistency
|
|
||||||
gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +40,10 @@ func (gui *Gui) handleCommitFileSelect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.getSelectedCommitFile()
|
||||||
|
if file == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := gui.GitCommand.CheckoutFile(file.Parent, file.Name); err != nil {
|
if err := gui.GitCommand.CheckoutFile(file.Parent, file.Name); err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
@ -113,7 +114,6 @@ func (gui *Gui) handleEditCommitFile(g *gocui.Gui, v *gocui.View) error {
|
|||||||
func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
|
||||||
commitFile := gui.getSelectedCommitFile()
|
commitFile := gui.getSelectedCommitFile()
|
||||||
if commitFile == nil {
|
if commitFile == nil {
|
||||||
gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,6 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
|
|||||||
func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
|
func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
|
||||||
commitFile := gui.getSelectedCommitFile()
|
commitFile := gui.getSelectedCommitFile()
|
||||||
if commitFile == nil {
|
if commitFile == nil {
|
||||||
gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error {
|
|||||||
// get diff from commit file that's currently selected
|
// get diff from commit file that's currently selected
|
||||||
commitFile := gui.getSelectedCommitFile()
|
commitFile := gui.getSelectedCommitFile()
|
||||||
if commitFile == nil {
|
if commitFile == nil {
|
||||||
gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +75,6 @@ func (gui *Gui) handleToggleSelectionForPatch(g *gocui.Gui, v *gocui.View) error
|
|||||||
// add range of lines to those set for the file
|
// add range of lines to those set for the file
|
||||||
commitFile := gui.getSelectedCommitFile()
|
commitFile := gui.getSelectedCommitFile()
|
||||||
if commitFile == nil {
|
if commitFile == nil {
|
||||||
gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetCommitFileListDisplayStrings(commitFiles []*commands.CommitFile, diffName string) [][]string {
|
func GetCommitFileListDisplayStrings(commitFiles []*commands.CommitFile, diffName string) [][]string {
|
||||||
|
if len(commitFiles) == 0 {
|
||||||
|
return [][]string{{utils.ColoredString("(none)", color.FgRed)}}
|
||||||
|
}
|
||||||
|
|
||||||
lines := make([][]string, len(commitFiles))
|
lines := make([][]string, len(commitFiles))
|
||||||
|
|
||||||
for i := range commitFiles {
|
for i := range commitFiles {
|
||||||
@ -54,6 +58,6 @@ func getColorForChangeStatus(changeStatus string) color.Attribute {
|
|||||||
case "T":
|
case "T":
|
||||||
return color.FgMagenta
|
return color.FgMagenta
|
||||||
default:
|
default:
|
||||||
return color.FgWhite
|
return theme.DefaultTextColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user