mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
Merge pull request #279 from jesseduffield/hotfix/file-ordering
Restore old file merging algorithm
This commit is contained in:
commit
79940b7ba9
@ -173,28 +173,37 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []File) []File {
|
|||||||
return newFiles
|
return newFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
headResults := []File{}
|
appendedIndexes := []int{}
|
||||||
tailResults := []File{}
|
|
||||||
|
|
||||||
for _, newFile := range newFiles {
|
|
||||||
var isHeadResult bool
|
|
||||||
|
|
||||||
|
// retain position of files we already could see
|
||||||
|
result := []File{}
|
||||||
for _, oldFile := range oldFiles {
|
for _, oldFile := range oldFiles {
|
||||||
|
for newIndex, newFile := range newFiles {
|
||||||
if oldFile.Name == newFile.Name {
|
if oldFile.Name == newFile.Name {
|
||||||
isHeadResult = true
|
result = append(result, newFile)
|
||||||
|
appendedIndexes = append(appendedIndexes, newIndex)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isHeadResult {
|
|
||||||
headResults = append(headResults, newFile)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tailResults = append(tailResults, newFile)
|
// append any new files to the end
|
||||||
|
for index, newFile := range newFiles {
|
||||||
|
if !includesInt(appendedIndexes, index) {
|
||||||
|
result = append(result, newFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return append(headResults, tailResults...)
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func includesInt(list []int, a int) bool {
|
||||||
|
for _, b := range list {
|
||||||
|
if b == a {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBranchName branch name
|
// GetBranchName branch name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user