Files
lazygit/pkg/gui/filetree/file_node.go
Stefan Haller bc9fafff02 Make the conflict marker size a parameter of our marker matching
Git doesn't always write conflict markers of seven characters: the
conflict-marker-size gitattribute overrides that per file, and it is set
for good reasons — for file types whose regular content tends to contain
marker-looking lines, such as documentation about merging, or test
scripts. We hard-code seven characters everywhere we look for markers,
so none of that works.

Prepare for honoring the attribute by threading the marker size through
everything that recognizes a marker, carried on the file model. Nothing
fills it in yet, so we still use git's default size of seven everywhere,
and matching is unchanged: a marker consists of exactly that many marker
characters, and all but the "=======" one are followed by a space and a
label.
2026-08-08 12:43:42 +02:00

74 lines
1.6 KiB
Go

package filetree
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
)
// FileNode wraps a node and provides some file-specific methods for it.
type FileNode struct {
*Node[models.File]
}
var _ models.IFile = &FileNode{}
func NewFileNode(node *Node[models.File]) *FileNode {
if node == nil {
return nil
}
return &FileNode{Node: node}
}
// returns the underlying node, without any file-specific methods attached
func (self *FileNode) Raw() *Node[models.File] {
if self == nil {
return nil
}
return self.Node
}
func (self *FileNode) GetHasUnstagedChanges() bool {
return self.SomeFile(func(file *models.File) bool { return file.HasUnstagedChanges })
}
func (self *FileNode) GetHasStagedOrTrackedChanges() bool {
if !self.GetHasStagedChanges() {
return self.SomeFile(func(t *models.File) bool {
return t.Tracked
})
}
return true
}
func (self *FileNode) GetHasStagedChanges() bool {
return self.SomeFile(func(file *models.File) bool { return file.HasStagedChanges })
}
func (self *FileNode) GetHasInlineMergeConflicts() bool {
return self.SomeFile(func(file *models.File) bool {
if !file.HasInlineMergeConflicts {
return false
}
hasConflicts, _ := mergeconflicts.FileHasConflictMarkers(file.Path, file.ConflictMarkerSize)
return hasConflicts
})
}
func (self *FileNode) GetIsTracked() bool {
return self.SomeFile(func(file *models.File) bool { return file.Tracked })
}
func (self *FileNode) GetIsFile() bool {
return self.IsFile()
}
func (self *FileNode) GetPreviousPath() string {
if self.File == nil {
return ""
}
return self.File.PreviousPath
}