diff options
Diffstat (limited to 'pkg/commands/models')
-rw-r--r-- | pkg/commands/models/file_change_node.go | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/pkg/commands/models/file_change_node.go b/pkg/commands/models/file_change_node.go index 805a74439..c70db2dfa 100644 --- a/pkg/commands/models/file_change_node.go +++ b/pkg/commands/models/file_change_node.go @@ -16,26 +16,30 @@ type FileChangeNode struct { } func (s *FileChangeNode) GetHasUnstagedChanges() bool { - if s.IsLeaf() { - return s.File.HasUnstagedChanges - } + return s.AnyFile(func(file *File) bool { return file.HasUnstagedChanges }) +} - for _, child := range s.Children { - if child.GetHasUnstagedChanges() { - return true - } - } +func (s *FileChangeNode) GetHasStagedChanges() bool { + return s.AnyFile(func(file *File) bool { return file.HasStagedChanges }) +} - return false +func (s *FileChangeNode) GetHasInlineMergeConflicts() bool { + return s.AnyFile(func(file *File) bool { return file.HasInlineMergeConflicts }) } -func (s *FileChangeNode) GetHasStagedChanges() bool { - if s.IsLeaf() { - return s.File.HasStagedChanges +func (s *FileChangeNode) AnyFile(test func(file *File) bool) bool { + return s.Any(func(node *FileChangeNode) bool { + return node.IsLeaf() && test(node.File) + }) +} + +func (s *FileChangeNode) Any(test func(node *FileChangeNode) bool) bool { + if test(s) { + return true } for _, child := range s.Children { - if child.GetHasStagedChanges() { + if test(child) { return true } } |