1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-13 13:59:06 +02:00

drop Name field from status line node

This commit is contained in:
Jesse Duffield 2021-03-21 10:03:51 +11:00
parent 4782d8aa1f
commit 46b79c7c61
3 changed files with 13 additions and 16 deletions

View File

@ -11,7 +11,6 @@ import (
type StatusLineNode struct { type StatusLineNode struct {
Children []*StatusLineNode Children []*StatusLineNode
File *File File *File
Name string // e.g. 'mydir'
Path string // e.g. '/path/to/mydir' Path string // e.g. '/path/to/mydir'
Collapsed bool Collapsed bool
} }
@ -146,7 +145,7 @@ func (s *StatusLineNode) sortChildren() {
return false return false
} }
return sortedChildren[i].Name < sortedChildren[j].Name return sortedChildren[i].Path < sortedChildren[j].Path
}) })
// TODO: think about making this in-place // TODO: think about making this in-place
@ -243,7 +242,7 @@ func (s *StatusLineNode) ForEachFile(cb func(*File) error) error {
} }
func (s *StatusLineNode) NameAtDepth(depth int) string { func (s *StatusLineNode) NameAtDepth(depth int) string {
splitName := strings.Split(s.Name, string(os.PathSeparator)) splitName := strings.Split(s.Path, string(os.PathSeparator))
name := filepath.Join(splitName[depth:]...) name := filepath.Join(splitName[depth:]...)
if s.File != nil && s.File.IsRename() { if s.File != nil && s.File.IsRename() {

View File

@ -21,9 +21,9 @@ func TestRender(t *testing.T) {
{ {
name: "leaf node", name: "leaf node",
root: &models.StatusLineNode{ root: &models.StatusLineNode{
Name: "", Path: "",
Children: []*models.StatusLineNode{ Children: []*models.StatusLineNode{
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Name: "test"}, {File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
}, },
}, },
expected: []string{" M test"}, expected: []string{" M test"},
@ -31,43 +31,43 @@ func TestRender(t *testing.T) {
{ {
name: "big example", name: "big example",
root: &models.StatusLineNode{ root: &models.StatusLineNode{
Name: "", Path: "",
Children: []*models.StatusLineNode{ Children: []*models.StatusLineNode{
{ {
Name: "dir1", Path: "dir1",
Collapsed: true, Collapsed: true,
Children: []*models.StatusLineNode{ Children: []*models.StatusLineNode{
{ {
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
Name: "file2", Path: "file2",
}, },
}, },
}, },
{ {
Name: "dir2", Path: "dir2",
Children: []*models.StatusLineNode{ Children: []*models.StatusLineNode{
{ {
Name: "dir2", Path: "dir2",
Children: []*models.StatusLineNode{ Children: []*models.StatusLineNode{
{ {
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
Name: "file3", Path: "file3",
}, },
{ {
File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
Name: "file4", Path: "file4",
}, },
}, },
}, },
{ {
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
Name: "file5", Path: "file5",
}, },
}, },
}, },
{ {
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
Name: "file1", Path: "file1",
}, },
}, },
}, },

View File

@ -35,7 +35,6 @@ func GetTreeFromStatusFiles(files []*models.File, log *logrus.Entry) *models.Sta
} }
newChild := &models.StatusLineNode{ newChild := &models.StatusLineNode{
Name: path, // TODO: Remove concept of name
Path: path, Path: path,
File: setFile, File: setFile,
} }
@ -55,7 +54,6 @@ func GetFlatTreeFromStatusFiles(files []*models.File) *models.StatusLineNode {
root := &models.StatusLineNode{} root := &models.StatusLineNode{}
for _, file := range files { for _, file := range files {
root.Children = append(root.Children, &models.StatusLineNode{ root.Children = append(root.Children, &models.StatusLineNode{
Name: file.GetPath(),
Path: file.GetPath(), Path: file.GetPath(),
File: file, File: file,
}) })