1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/working_tree_helper.go

50 lines
988 B
Go
Raw Normal View History

package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
type WorkingTreeHelper struct {
2022-01-30 04:08:09 +02:00
getFiles func() []*models.File
}
2022-01-30 04:08:09 +02:00
func NewWorkingTreeHelper(getFiles func() []*models.File) *WorkingTreeHelper {
return &WorkingTreeHelper{
2022-01-30 04:08:09 +02:00
getFiles: getFiles,
}
}
func (self *WorkingTreeHelper) AnyStagedFiles() bool {
2022-01-30 04:08:09 +02:00
files := self.getFiles()
for _, file := range files {
if file.HasStagedChanges {
return true
}
}
return false
}
func (self *WorkingTreeHelper) AnyTrackedFiles() bool {
2022-01-30 04:08:09 +02:00
files := self.getFiles()
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 {
2022-01-30 04:08:09 +02:00
for _, file := range self.getFiles() {
if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) {
return file
}
}
return nil
}