1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-21 22:43:27 +02:00

picking up new files upon file refresh

This commit is contained in:
Jesse Duffield 2018-06-02 09:05:20 +10:00
parent 5ccea4f5d9
commit 7cdcef8c93

View File

@ -70,7 +70,18 @@ func Map(vs []string, f func(string) string) []string {
return vsm return vsm
} }
func includes(list []string, a string) bool { func includesString(list []string, a string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
// not sure how to genericise this because []interface{} doesn't accept e.g.
// []int arguments
func includesInt(list []int, a int) bool {
for _, b := range list { for _, b := range list {
if b == a { if b == a {
return true return true
@ -84,15 +95,27 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile {
return newGitFiles return newGitFiles
} }
appendedIndexes := make([]int, 0)
// retain position of files we already could see
result := make([]GitFile, 0) result := make([]GitFile, 0)
for _, oldGitFile := range oldGitFiles { for _, oldGitFile := range oldGitFiles {
for _, newGitFile := range newGitFiles { for newIndex, newGitFile := range newGitFiles {
if oldGitFile.Name == newGitFile.Name { if oldGitFile.Name == newGitFile.Name {
result = append(result, newGitFile) result = append(result, newGitFile)
appendedIndexes = append(appendedIndexes, newIndex)
break break
} }
} }
} }
// append any new files to the end
for index, newGitFile := range newGitFiles {
if !includesInt(appendedIndexes, index) {
result = append(result, newGitFile)
}
}
return result return result
} }
@ -230,7 +253,7 @@ func getCommits() []Commit {
for _, line := range lines { for _, line := range lines {
splitLine := strings.Split(line, " ") splitLine := strings.Split(line, " ")
sha := splitLine[0] sha := splitLine[0]
pushed := includes(pushables, sha) pushed := includesString(pushables, sha)
commits = append(commits, Commit{ commits = append(commits, Commit{
Sha: sha, Sha: sha,
Name: strings.Join(splitLine[1:], " "), Name: strings.Join(splitLine[1:], " "),