2021-03-21 06:58:15 +02:00
|
|
|
package filetree
|
2020-11-15 01:45:55 +02:00
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
import "github.com/jesseduffield/lazygit/pkg/commands/models"
|
2020-11-15 01:45:55 +02:00
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
// FileNode wraps a node and provides some file-specific methods for it.
|
2021-03-31 14:26:53 +02:00
|
|
|
type FileNode struct {
|
2022-07-31 11:10:16 +02:00
|
|
|
*Node[models.File]
|
2020-11-15 01:45:55 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
var _ models.IFile = &FileNode{}
|
2020-11-15 01:45:55 +02:00
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
func NewFileNode(node *Node[models.File]) *FileNode {
|
2021-04-03 04:43:43 +02:00
|
|
|
if node == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
return &FileNode{Node: node}
|
2020-11-15 01:45:55 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
// returns the underlying node, without any file-specific methods attached
|
|
|
|
func (self *FileNode) Raw() *Node[models.File] {
|
2022-08-01 12:32:01 +02:00
|
|
|
if self == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
return self.Node
|
2020-11-15 01:45:55 +02:00
|
|
|
}
|
2021-03-14 09:46:22 +02:00
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
func (self *FileNode) GetHasUnstagedChanges() bool {
|
|
|
|
return self.SomeFile(func(file *models.File) bool { return file.HasUnstagedChanges })
|
2021-03-14 09:46:22 +02:00
|
|
|
}
|
2021-03-14 10:38:59 +02:00
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
func (self *FileNode) GetHasStagedChanges() bool {
|
|
|
|
return self.SomeFile(func(file *models.File) bool { return file.HasStagedChanges })
|
2021-03-14 10:38:59 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
func (self *FileNode) GetHasInlineMergeConflicts() bool {
|
|
|
|
return self.SomeFile(func(file *models.File) bool { return file.HasInlineMergeConflicts })
|
2021-03-30 14:56:59 +02:00
|
|
|
}
|
2021-03-14 10:38:59 +02:00
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
func (self *FileNode) GetIsTracked() bool {
|
|
|
|
return self.SomeFile(func(file *models.File) bool { return file.Tracked })
|
2021-03-14 11:23:06 +02:00
|
|
|
}
|
2021-03-15 13:29:34 +02:00
|
|
|
|
2022-11-11 03:16:38 +02:00
|
|
|
func (self *FileNode) GetIsFile() bool {
|
|
|
|
return self.IsFile()
|
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
func (self *FileNode) GetPreviousPath() string {
|
|
|
|
if self.File == nil {
|
|
|
|
return ""
|
2021-03-21 01:46:43 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 11:10:16 +02:00
|
|
|
return self.File.PreviousName
|
2021-03-21 01:46:43 +02:00
|
|
|
}
|