diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-12 18:26:29 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 18:26:29 +1000 |
commit | 79940b7ba9047965cbe35f159eac3d133e229da7 (patch) | |
tree | 86ae0b841e228a610581d6de7dc866d722b98c54 /pkg/commands | |
parent | 73e2c1005abf874faed2a2777ac39c78eef02c0e (diff) | |
parent | 2ce8ac585012bde2493cdfa55132381200629700 (diff) |
Merge pull request #279 from jesseduffield/hotfix/file-ordering
Restore old file merging algorithm
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 624588fc2..5744fa6aa 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -173,28 +173,37 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []File) []File { return newFiles } - headResults := []File{} - tailResults := []File{} + appendedIndexes := []int{} - for _, newFile := range newFiles { - var isHeadResult bool - - for _, oldFile := range oldFiles { + // retain position of files we already could see + result := []File{} + for _, oldFile := range oldFiles { + for newIndex, newFile := range newFiles { if oldFile.Name == newFile.Name { - isHeadResult = true + result = append(result, newFile) + appendedIndexes = append(appendedIndexes, newIndex) break } } + } - if isHeadResult { - headResults = append(headResults, newFile) - continue + // append any new files to the end + for index, newFile := range newFiles { + if !includesInt(appendedIndexes, index) { + result = append(result, newFile) } - - tailResults = append(tailResults, 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 |