1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/working_tree_helper.go
2022-03-17 19:13:40 +11:00

51 lines
1.2 KiB
Go

package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
)
type WorkingTreeHelper struct {
getFileTreeViewModel func() *filetree.FileTreeViewModel
}
func NewWorkingTreeHelper(getFileTreeViewModel func() *filetree.FileTreeViewModel) *WorkingTreeHelper {
return &WorkingTreeHelper{
getFileTreeViewModel: getFileTreeViewModel,
}
}
func (self *WorkingTreeHelper) AnyStagedFiles() bool {
files := self.getFileTreeViewModel().GetAllFiles()
for _, file := range files {
if file.HasStagedChanges {
return true
}
}
return false
}
func (self *WorkingTreeHelper) AnyTrackedFiles() bool {
files := self.getFileTreeViewModel().GetAllFiles()
for _, file := range files {
if file.Tracked {
return true
}
}
return false
}
func (self *WorkingTreeHelper) IsWorkingTreeDirty() bool {
return self.AnyStagedFiles() || self.AnyTrackedFiles()
}
func (self *WorkingTreeHelper) FileForSubmodule(submodule *models.SubmoduleConfig) *models.File {
for _, file := range self.getFileTreeViewModel().GetAllFiles() {
if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) {
return file
}
}
return nil
}