summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAnthony HAMON <anthony.hamon@iadvize.com>2018-08-28 21:09:56 +0200
committerAnthony HAMON <hamon.anth@gmail.com>2018-08-29 12:03:32 +0200
commite3ed899b20c1e1cec25245bcb32c272ad02580fd (patch)
tree225c397966acbfbf023771d768ccb99afd6b9fe0 /pkg
parentd6b4d4b063e4def1fbdeea5a90e31cdb2fb1a00b (diff)
refactor MergeStatusFiles
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git.go37
1 files changed, 13 insertions, 24 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 0cedb2150..619db05e7 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -121,28 +121,28 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []File) []File {
return newFiles
}
- appendedIndexes := []int{}
+ headResults := []File{}
+ tailResults := []File{}
- // retain position of files we already could see
- result := []File{}
- for _, oldFile := range oldFiles {
- for newIndex, newFile := range newFiles {
+ for _, newFile := range newFiles {
+ var isHeadResult bool
+
+ for _, oldFile := range oldFiles {
if oldFile.Name == newFile.Name {
- result = append(result, newFile)
- appendedIndexes = append(appendedIndexes, newIndex)
+ isHeadResult = true
break
}
}
- }
- // append any new files to the end
- for index, newFile := range newFiles {
- if !includesInt(appendedIndexes, index) {
- result = append(result, newFile)
+ if isHeadResult {
+ headResults = append(headResults, newFile)
+ continue
}
+
+ tailResults = append(tailResults, newFile)
}
- return result
+ return append(headResults, tailResults...)
}
func (c *GitCommand) verifyInGitRepo() {
@@ -447,17 +447,6 @@ func includesString(list []string, a string) bool {
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
func (c *GitCommand) GetCommits() []Commit {
pushables := c.GetCommitsToPush()