Add a <root> item if files at top level have changed

This commit is contained in:
Stefan Haller
2025-03-01 07:25:26 +01:00
parent 7579a80dce
commit 5c2e7a7571
3 changed files with 21 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ func BuildTreeFromFiles(files []*models.File) *Node[models.File] {
var curr *Node[models.File]
for _, file := range files {
splitPath := split(file.Path)
splitPath := split("./" + file.Path)
curr = root
outer:
for i := range splitPath {
@@ -70,7 +70,7 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *Node[models.CommitFil
var curr *Node[models.CommitFile]
for _, file := range files {
splitPath := split(file.Path)
splitPath := split("./" + file.Path)
curr = root
outer:
for i := range splitPath {

View File

@@ -2,6 +2,7 @@ package filetree
import (
"path"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -47,6 +48,10 @@ func (self *Node[T]) GetFile() *T {
}
func (self *Node[T]) GetPath() string {
return strings.TrimPrefix(self.path, "./")
}
func (self *Node[T]) GetFullPath() string {
return self.path
}

View File

@@ -293,7 +293,13 @@ func getColorForChangeStatus(changeStatus string) style.TextStyle {
}
func fileNameAtDepth(node *filetree.Node[models.File], depth int) string {
splitName := split(node.GetPath())
splitName := split(node.GetFullPath())
if depth == 0 {
if len(splitName) == 1 {
return "<root>"
}
depth = 1
}
name := join(splitName[depth:])
if node.File != nil && node.File.IsRename() {
@@ -314,7 +320,13 @@ func fileNameAtDepth(node *filetree.Node[models.File], depth int) string {
}
func commitFileNameAtDepth(node *filetree.Node[models.CommitFile], depth int) string {
splitName := split(node.GetPath())
splitName := split(node.GetFullPath())
if depth == 0 {
if len(splitName) == 1 {
return "<root>"
}
depth = 1
}
name := join(splitName[depth:])
return name