mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
Add free-standing function IsWorkingTreeDirty
The long story: I want to call this function from RefsHelper; however, I can't make WorkingTreeHelper a field of RefsHelper because RefsHelper is already a field in WorkingTreeHelper, so that would be a circular dependency. The shorter story: there's really little reason to have to instantiate a helper object in order to call a simple function like this. Long term I would like to get to a state where a lot more of these helper functions are free-standing, and you pass in the data they need. While at it, simplify the implementation of AnyStagedFiles and AnyTrackedFiles to one-liners.
This commit is contained in:
parent
9d88d6a44e
commit
4bf11eae4b
1 changed files with 16 additions and 13 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type WorkingTreeHelper struct {
|
||||
|
@ -34,25 +35,27 @@ func NewWorkingTreeHelper(
|
|||
}
|
||||
|
||||
func (self *WorkingTreeHelper) AnyStagedFiles() bool {
|
||||
for _, file := range self.c.Model().Files {
|
||||
if file.HasStagedChanges {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return AnyStagedFiles(self.c.Model().Files)
|
||||
}
|
||||
|
||||
func AnyStagedFiles(files []*models.File) bool {
|
||||
return lo.SomeBy(files, func(f *models.File) bool { return f.HasStagedChanges })
|
||||
}
|
||||
|
||||
func (self *WorkingTreeHelper) AnyTrackedFiles() bool {
|
||||
for _, file := range self.c.Model().Files {
|
||||
if file.Tracked {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return AnyTrackedFiles(self.c.Model().Files)
|
||||
}
|
||||
|
||||
func AnyTrackedFiles(files []*models.File) bool {
|
||||
return lo.SomeBy(files, func(f *models.File) bool { return f.Tracked })
|
||||
}
|
||||
|
||||
func (self *WorkingTreeHelper) IsWorkingTreeDirty() bool {
|
||||
return self.AnyStagedFiles() || self.AnyTrackedFiles()
|
||||
return IsWorkingTreeDirty(self.c.Model().Files)
|
||||
}
|
||||
|
||||
func IsWorkingTreeDirty(files []*models.File) bool {
|
||||
return AnyStagedFiles(files) || AnyTrackedFiles(files)
|
||||
}
|
||||
|
||||
func (self *WorkingTreeHelper) FileForSubmodule(submodule *models.SubmoduleConfig) *models.File {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue