From 1183f68e19d26a63293cfab1650a59f3b90a844b Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 21 Mar 2021 09:06:15 +1100 Subject: better handling of refreshed files --- pkg/commands/git_test.go | 81 ------------------------------------------- pkg/commands/loading_files.go | 35 ------------------- 2 files changed, 116 deletions(-) (limited to 'pkg/commands') diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index e0955932f..90c32c7dd 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -461,87 +461,6 @@ func TestGitCommandCommitAmend(t *testing.T) { assert.NoError(t, err) } -// TestGitCommandMergeStatusFiles is a function. -func TestGitCommandMergeStatusFiles(t *testing.T) { - type scenario struct { - testName string - oldFiles []*models.File - newFiles []*models.File - test func([]*models.File) - } - - scenarios := []scenario{ - { - "Old file and new file are the same", - []*models.File{}, - []*models.File{ - { - Name: "new_file.txt", - }, - }, - func(files []*models.File) { - expected := []*models.File{ - { - Name: "new_file.txt", - }, - } - - assert.Len(t, files, 1) - assert.EqualValues(t, expected, files) - }, - }, - { - "Several files to merge, with some identical", - []*models.File{ - { - Name: "new_file1.txt", - }, - { - Name: "new_file2.txt", - }, - { - Name: "new_file3.txt", - }, - }, - []*models.File{ - { - Name: "new_file4.txt", - }, - { - Name: "new_file5.txt", - }, - { - Name: "new_file1.txt", - }, - }, - func(files []*models.File) { - expected := []*models.File{ - { - Name: "new_file1.txt", - }, - { - Name: "new_file4.txt", - }, - { - Name: "new_file5.txt", - }, - } - - assert.Len(t, files, 3) - assert.EqualValues(t, expected, files) - }, - }, - } - - for _, s := range scenarios { - t.Run(s.testName, func(t *testing.T) { - gitCmd := NewDummyGitCommand() - - s.test(gitCmd.MergeStatusFiles(s.oldFiles, s.newFiles, nil)) - }) - } -} - // TestGitCommandGetCommitDifferences is a function. func TestGitCommandGetCommitDifferences(t *testing.T) { type scenario struct { diff --git a/pkg/commands/loading_files.go b/pkg/commands/loading_files.go index ba3244999..d3757b179 100644 --- a/pkg/commands/loading_files.go +++ b/pkg/commands/loading_files.go @@ -102,38 +102,3 @@ func (c *GitCommand) GitStatus(opts GitStatusOptions) (string, error) { return strings.Join(splitLines, "\n"), nil } - -// MergeStatusFiles merge status files -func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*models.File, selectedFile *models.File) []*models.File { - if len(oldFiles) == 0 { - return newFiles - } - - appendedIndexes := []int{} - - // retain position of files we already could see - result := []*models.File{} - for _, oldFile := range oldFiles { - for newIndex, newFile := range newFiles { - if utils.IncludesInt(appendedIndexes, newIndex) { - continue - } - // if we just staged B and in doing so created 'A -> B' and we are currently have oldFile: A and newFile: 'A -> B', we want to wait until we come across B so the our cursor isn't jumping anywhere - waitForMatchingFile := selectedFile != nil && newFile.IsRename() && !selectedFile.IsRename() && newFile.Matches(selectedFile) && !oldFile.Matches(selectedFile) - - if oldFile.Matches(newFile) && !waitForMatchingFile { - result = append(result, newFile) - appendedIndexes = append(appendedIndexes, newIndex) - } - } - } - - // append any new files to the end - for index, newFile := range newFiles { - if !utils.IncludesInt(appendedIndexes, index) { - result = append(result, newFile) - } - } - - return result -} -- cgit v1.2.3