2018-09-17 13:02:30 +02:00
|
|
|
package commands
|
|
|
|
|
2020-08-07 10:27:18 +02:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
|
|
)
|
2020-08-07 09:52:17 +02:00
|
|
|
|
2018-09-17 13:02:30 +02:00
|
|
|
// File : A file from git status
|
|
|
|
// duplicating this for now
|
|
|
|
type File struct {
|
2019-03-03 06:55:19 +02:00
|
|
|
Name string
|
|
|
|
HasStagedChanges bool
|
|
|
|
HasUnstagedChanges bool
|
|
|
|
Tracked bool
|
|
|
|
Deleted bool
|
|
|
|
HasMergeConflicts bool
|
|
|
|
HasInlineMergeConflicts bool
|
|
|
|
DisplayString string
|
|
|
|
Type string // one of 'file', 'directory', and 'other'
|
2019-05-30 14:45:56 +02:00
|
|
|
ShortStatus string // e.g. 'AD', ' A', 'M ', '??'
|
2018-09-17 13:02:30 +02:00
|
|
|
}
|
2020-08-07 09:52:17 +02:00
|
|
|
|
2020-08-07 10:27:18 +02:00
|
|
|
const RENAME_SEPARATOR = " -> "
|
|
|
|
|
2020-08-07 09:52:17 +02:00
|
|
|
func (f *File) IsRename() bool {
|
2020-08-07 10:27:18 +02:00
|
|
|
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 09:52:17 +02:00
|
|
|
}
|
2020-08-22 00:49:02 +02:00
|
|
|
|
|
|
|
func (f *File) ID() string {
|
|
|
|
return f.Name
|
|
|
|
}
|
2020-08-22 02:14:53 +02:00
|
|
|
|
|
|
|
func (f *File) Description() string {
|
|
|
|
return f.Name
|
|
|
|
}
|