diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-21 15:44:10 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-30 21:57:00 +1100 |
commit | 9e67f74ca32d4422df13bc1ffeb1e7d639c11639 (patch) | |
tree | d71abae9157c01d955b2f7fab6d8453aecc54c4d /pkg/commands | |
parent | e3ddfbf2b84da0e767ac02be721dcd8155b6143f (diff) |
prevent staging directory containing files with inline merge conflicts
Diffstat (limited to 'pkg/commands')
-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 } } |