mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
refactor MergeStatusFiles
This commit is contained in:
committed by
Anthony HAMON
parent
d6b4d4b063
commit
e3ed899b20
@ -121,28 +121,28 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []File) []File {
|
|||||||
return newFiles
|
return newFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
appendedIndexes := []int{}
|
headResults := []File{}
|
||||||
|
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 {
|
||||||
result = append(result, newFile)
|
isHeadResult = true
|
||||||
appendedIndexes = append(appendedIndexes, newIndex)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isHeadResult {
|
||||||
|
headResults = append(headResults, newFile)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// append any new files to the end
|
tailResults = append(tailResults, newFile)
|
||||||
for index, newFile := range newFiles {
|
|
||||||
if !includesInt(appendedIndexes, index) {
|
|
||||||
result = append(result, newFile)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return append(headResults, tailResults...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) verifyInGitRepo() {
|
func (c *GitCommand) verifyInGitRepo() {
|
||||||
@ -447,17 +447,6 @@ func includesString(list []string, a string) bool {
|
|||||||
return false
|
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 {
|
|
||||||
if b == a {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCommits obtains the commits of the current branch
|
// GetCommits obtains the commits of the current branch
|
||||||
func (c *GitCommand) GetCommits() []Commit {
|
func (c *GitCommand) GetCommits() []Commit {
|
||||||
pushables := c.GetCommitsToPush()
|
pushables := c.GetCommitsToPush()
|
||||||
|
Reference in New Issue
Block a user