summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-03-14 20:23:06 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-03-30 21:57:00 +1100
commitdef68ddc8f91b01ce66fca1ea18561b864f3801b (patch)
treec7f55dc1e32a1c915d56abaef421e1bef0ad3abf /pkg/commands
parenta31db3df9c73879f61ab492d220e3af7d1765661 (diff)
fix bug for combining directories with single child
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/models/status_line_node.go16
-rw-r--r--pkg/commands/models/status_line_node_test.go22
2 files changed, 30 insertions, 8 deletions
diff --git a/pkg/commands/models/status_line_node.go b/pkg/commands/models/status_line_node.go
index 1ac8bcdd7..3ed1a573a 100644
--- a/pkg/commands/models/status_line_node.go
+++ b/pkg/commands/models/status_line_node.go
@@ -157,10 +157,6 @@ func (s *StatusLineNode) GetPath() string {
return s.Path
}
-func (s *StatusLineNode) HasExactlyOneChild() bool {
- return len(s.Children) == 1
-}
-
func (s *StatusLineNode) Compress() {
if s == nil {
return
@@ -174,10 +170,10 @@ func (s *StatusLineNode) compressAux() *StatusLineNode {
return s
}
- for i, child := range s.Children {
- if child.HasExactlyOneChild() {
- grandchild := child.Children[0]
- grandchild.Name = fmt.Sprintf("%s/%s", child.Name, grandchild.Name)
+ for i := range s.Children {
+ for s.Children[i].HasExactlyOneChild() {
+ grandchild := s.Children[i].Children[0]
+ grandchild.Name = fmt.Sprintf("%s/%s", s.Children[i].Name, grandchild.Name)
s.Children[i] = grandchild
}
}
@@ -188,3 +184,7 @@ func (s *StatusLineNode) compressAux() *StatusLineNode {
return s
}
+
+func (s *StatusLineNode) HasExactlyOneChild() bool {
+ return len(s.Children) == 1
+}
diff --git a/pkg/commands/models/status_line_node_test.go b/pkg/commands/models/status_line_node_test.go
index c68199c18..5f0a1a853 100644
--- a/pkg/commands/models/status_line_node_test.go
+++ b/pkg/commands/models/status_line_node_test.go
@@ -65,6 +65,23 @@ func TestCompress(t *testing.T) {
},
},
{
+ Name: "dir3",
+ Path: "dir3",
+ Children: []*StatusLineNode{
+ {
+ Name: "dir3-1",
+ Path: "dir3/dir3-1",
+ Children: []*StatusLineNode{
+ {
+ File: &File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
+ Name: "file5",
+ Path: "dir3/dir3-1/file5",
+ },
+ },
+ },
+ },
+ },
+ {
File: &File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
Name: "file1",
Path: "file1",
@@ -96,6 +113,11 @@ func TestCompress(t *testing.T) {
},
},
{
+ Name: "dir3/dir3-1/file5",
+ File: &File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
+ Path: "dir3/dir3-1/file5",
+ },
+ {
File: &File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
Name: "file1",
Path: "file1",