1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00

79 lines
1.8 KiB
Go
Raw Normal View History

2020-09-29 18:45:00 +10:00
package models
import (
"strings"
"github.com/jesseduffield/lazygit/pkg/utils"
)
2020-08-07 17:52:17 +10:00
// File : A file from git status
// duplicating this for now
type File struct {
Name string
HasStagedChanges bool
HasUnstagedChanges bool
Tracked bool
2021-03-20 12:07:11 +11: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 17:52:17 +10:00
const RENAME_SEPARATOR = " -> "
2020-08-07 17:52:17 +10:00
func (f *File) IsRename() bool {
return strings.Contains(f.Name, RENAME_SEPARATOR)
}
// 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 {
return strings.Split(f.Name, RENAME_SEPARATOR)
}
// 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 17:52:17 +10:00
}
2020-08-22 08:49:02 +10:00
func (f *File) ID() string {
return f.Name
}
func (f *File) Description() string {
return f.Name
}
2020-09-28 09:14:32 +10: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 18:46:22 +11: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 {
names := f.Names()
return names[len(names)-1]
}