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

90 lines
2.0 KiB
Go
Raw Normal View History

2020-09-29 10:45:00 +02:00
package models
import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
2020-08-07 09:52:17 +02:00
// File : A file from git status
// duplicating this for now
type File struct {
Name string
2021-03-20 23:41:06 +02:00
PreviousName string
HasStagedChanges bool
HasUnstagedChanges bool
Tracked bool
2021-03-20 03:07:11 +02:00
Added bool
Deleted bool
HasMergeConflicts bool
HasInlineMergeConflicts bool
DisplayString string
Type string // one of 'file', 'directory', and 'other'
ShortStatus string // e.g. 'AD', ' A', 'M ', '??'
}
2020-08-07 09:52:17 +02:00
2021-03-21 06:58:15 +02:00
// sometimes we need to deal with either a node (which contains a file) or an actual file
type IFile interface {
2021-03-21 06:58:15 +02:00
GetHasUnstagedChanges() bool
GetHasStagedChanges() bool
GetIsTracked() bool
GetPath() string
}
const RENAME_SEPARATOR = " -> "
2020-08-07 09:52:17 +02:00
func (f *File) IsRename() bool {
2021-03-20 23:41:06 +02:00
return f.PreviousName != ""
}
// Names returns an array containing just the filename, or in the case of a rename, the after filename and the before filename
func (f *File) Names() []string {
2021-03-20 23:41:06 +02:00
result := []string{f.Name}
if f.PreviousName != "" {
result = append(result, f.PreviousName)
}
return result
}
// returns true if the file names are the same or if a a file rename includes the filename of the other
func (f *File) Matches(f2 *File) bool {
return utils.StringArraysOverlap(f.Names(), f2.Names())
2020-08-07 09:52:17 +02:00
}
2020-08-22 00:49:02 +02:00
func (f *File) ID() string {
return f.Name
}
func (f *File) Description() string {
return f.Name
}
2020-09-28 01:14:32 +02:00
func (f *File) IsSubmodule(configs []*SubmoduleConfig) bool {
return f.SubmoduleConfig(configs) != nil
}
func (f *File) SubmoduleConfig(configs []*SubmoduleConfig) *SubmoduleConfig {
for _, config := range configs {
if f.Name == config.Name {
return config
}
}
return nil
}
2021-03-14 09:46:22 +02:00
func (f *File) GetHasUnstagedChanges() bool {
return f.HasUnstagedChanges
}
func (f *File) GetHasStagedChanges() bool {
return f.HasStagedChanges
}
func (f *File) GetIsTracked() bool {
return f.Tracked
}
func (f *File) GetPath() string {
2021-03-20 23:41:06 +02:00
// TODO: remove concept of name; just use path
return f.Name
2021-03-14 09:46:22 +02:00
}