1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

remove collapsed field

This commit is contained in:
Jesse Duffield
2021-03-21 15:01:13 +11:00
parent f742434043
commit ef204b0adf
3 changed files with 14 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package models package models
// sometimes we need to deal with either a node (which contains a file) or an actual file
type IFileChange interface { type IFileChange interface {
GetHasUnstagedChanges() bool GetHasUnstagedChanges() bool
GetHasStagedChanges() bool GetHasStagedChanges() bool

View File

@ -12,8 +12,7 @@ type FileChangeNode struct {
Children []*FileChangeNode Children []*FileChangeNode
File *File File *File
Path string // e.g. '/path/to/mydir' Path string // e.g. '/path/to/mydir'
Collapsed bool CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode
CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode
} }
func (s *FileChangeNode) GetHasUnstagedChanges() bool { func (s *FileChangeNode) GetHasUnstagedChanges() bool {

View File

@ -9,9 +9,10 @@ import (
func TestRender(t *testing.T) { func TestRender(t *testing.T) {
scenarios := []struct { scenarios := []struct {
name string name string
root *models.FileChangeNode root *models.FileChangeNode
expected []string collapsedPaths map[string]bool
expected []string
}{ }{
{ {
name: "nil node", name: "nil node",
@ -34,13 +35,16 @@ func TestRender(t *testing.T) {
Path: "", Path: "",
Children: []*models.FileChangeNode{ Children: []*models.FileChangeNode{
{ {
Path: "dir1", Path: "dir1",
Collapsed: true,
Children: []*models.FileChangeNode{ Children: []*models.FileChangeNode{
{ {
File: &models.File{Name: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true}, File: &models.File{Name: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir1/file2", Path: "dir1/file2",
}, },
{
File: &models.File{Name: "dir1/file3", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir1/file3",
},
}, },
}, },
{ {
@ -71,15 +75,15 @@ func TestRender(t *testing.T) {
}, },
}, },
}, },
expected: []string{"dir1 ►", "dir2 ▼", "├─ dir2 ▼", "│ ├─ M file3", "│ └─ M file4", "└─ M file5", "M file1"},
expected: []string{"dir1 ▼", "└─ M file2", "dir2 ▼", "├─ dir2 ▼", "│ ├─ M file3", "│ └─ M file4", "└─ M file5", "M file1"}, collapsedPaths: map[string]bool{"dir1": true},
}, },
} }
for _, s := range scenarios { for _, s := range scenarios {
s := s s := s
t.Run(s.name, func(t *testing.T) { t.Run(s.name, func(t *testing.T) {
mngr := &FileChangeManager{Tree: s.root} mngr := &FileChangeManager{Tree: s.root, CollapsedPaths: s.collapsedPaths}
result := mngr.Render("", nil) result := mngr.Render("", nil)
assert.EqualValues(t, s.expected, result) assert.EqualValues(t, s.expected, result)
}) })