From 2dfc3491bd47ea4ba7cd8d3a52330b8d38a64963 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 28 Feb 2025 20:59:09 +0100 Subject: [PATCH] Rename Name to Path in File and CommitFile Name was very confusing and misleading. --- .../git_commands/commit_file_loader.go | 2 +- .../git_commands/commit_file_loader_test.go | 12 +- pkg/commands/git_commands/file_loader.go | 22 +-- pkg/commands/git_commands/file_loader_test.go | 22 +-- pkg/commands/git_commands/working_tree.go | 18 +-- .../git_commands/working_tree_test.go | 32 ++--- pkg/commands/models/commit_file.go | 9 +- pkg/commands/models/file.go | 22 +-- .../controllers/commits_files_controller.go | 4 +- pkg/gui/controllers/files_controller.go | 4 +- pkg/gui/controllers/helpers/refresh_helper.go | 4 +- pkg/gui/filetree/build_tree.go | 4 +- pkg/gui/filetree/build_tree_test.go | 132 +++++++++--------- pkg/gui/filetree/commit_file_tree.go | 2 +- pkg/gui/filetree/file_node.go | 4 +- pkg/gui/filetree/file_node_test.go | 30 ++-- pkg/gui/filetree/file_tree.go | 2 +- pkg/gui/filetree/file_tree_test.go | 54 +++---- pkg/gui/filetree/file_tree_view_model.go | 6 +- pkg/gui/presentation/files.go | 8 +- pkg/gui/presentation/files_test.go | 36 ++--- .../custom_commands/session_state_loader.go | 6 +- 22 files changed, 217 insertions(+), 218 deletions(-) diff --git a/pkg/commands/git_commands/commit_file_loader.go b/pkg/commands/git_commands/commit_file_loader.go index 68faf31ca..33bd40e13 100644 --- a/pkg/commands/git_commands/commit_file_loader.go +++ b/pkg/commands/git_commands/commit_file_loader.go @@ -55,7 +55,7 @@ func getCommitFilesFromFilenames(filenames string) []*models.CommitFile { return lo.Map(lo.Chunk(lines, 2), func(chunk []string, _ int) *models.CommitFile { return &models.CommitFile{ ChangeStatus: chunk[0], - Name: chunk[1], + Path: chunk[1], } }) } diff --git a/pkg/commands/git_commands/commit_file_loader_test.go b/pkg/commands/git_commands/commit_file_loader_test.go index 8928f5204..ec91ec22e 100644 --- a/pkg/commands/git_commands/commit_file_loader_test.go +++ b/pkg/commands/git_commands/commit_file_loader_test.go @@ -23,7 +23,7 @@ func TestGetCommitFilesFromFilenames(t *testing.T) { input: "MM\x00Myfile\x00", output: []*models.CommitFile{ { - Name: "Myfile", + Path: "Myfile", ChangeStatus: "MM", }, }, @@ -33,11 +33,11 @@ func TestGetCommitFilesFromFilenames(t *testing.T) { input: "MM\x00Myfile\x00M \x00MyOtherFile\x00", output: []*models.CommitFile{ { - Name: "Myfile", + Path: "Myfile", ChangeStatus: "MM", }, { - Name: "MyOtherFile", + Path: "MyOtherFile", ChangeStatus: "M ", }, }, @@ -47,15 +47,15 @@ func TestGetCommitFilesFromFilenames(t *testing.T) { input: "MM\x00Myfile\x00M \x00MyOtherFile\x00 M\x00YetAnother\x00", output: []*models.CommitFile{ { - Name: "Myfile", + Path: "Myfile", ChangeStatus: "MM", }, { - Name: "MyOtherFile", + Path: "MyOtherFile", ChangeStatus: "M ", }, { - Name: "YetAnother", + Path: "YetAnother", ChangeStatus: " M", }, }, diff --git a/pkg/commands/git_commands/file_loader.go b/pkg/commands/git_commands/file_loader.go index dcc1615a7..bb898d06a 100644 --- a/pkg/commands/git_commands/file_loader.go +++ b/pkg/commands/git_commands/file_loader.go @@ -68,12 +68,12 @@ func (self *FileLoader) GetStatusFiles(opts GetStatusFileOptions) []*models.File } file := &models.File{ - Name: status.Name, - PreviousName: status.PreviousName, + Path: status.Path, + PreviousPath: status.PreviousPath, DisplayString: status.StatusString, } - if diff, ok := fileDiffs[status.Name]; ok { + if diff, ok := fileDiffs[status.Path]; ok { file.LinesAdded = diff.LinesAdded file.LinesDeleted = diff.LinesDeleted } @@ -87,7 +87,7 @@ func (self *FileLoader) GetStatusFiles(opts GetStatusFileOptions) []*models.File worktreePaths := linkedWortkreePaths(self.Fs, self.repoPaths.RepoGitDirPath()) for _, file := range files { for _, worktreePath := range worktreePaths { - absFilePath, err := filepath.Abs(file.Name) + absFilePath, err := filepath.Abs(file.Path) if err != nil { self.Log.Error(err) continue @@ -96,7 +96,7 @@ func (self *FileLoader) GetStatusFiles(opts GetStatusFileOptions) []*models.File file.IsWorktree = true // `git status` renders this worktree as a folder with a trailing slash but we'll represent it as a singular worktree // If we include the slash, it will be rendered as a folder with a null file inside. - file.Name = strings.TrimSuffix(file.Name, "/") + file.Path = strings.TrimSuffix(file.Path, "/") break } } @@ -153,8 +153,8 @@ type GitStatusOptions struct { type FileStatus struct { StatusString string Change string // ??, MM, AM, ... - Name string - PreviousName string + Path string + PreviousPath string } func (fileLoader *FileLoader) gitDiffNumStat() (string, error) { @@ -197,14 +197,14 @@ func (self *FileLoader) gitStatus(opts GitStatusOptions) ([]FileStatus, error) { status := FileStatus{ StatusString: original, Change: original[:2], - Name: original[3:], - PreviousName: "", + Path: original[3:], + PreviousPath: "", } if strings.HasPrefix(status.Change, "R") { // if a line starts with 'R' then the next line is the original file. - status.PreviousName = splitLines[i+1] - status.StatusString = fmt.Sprintf("%s %s -> %s", status.Change, status.PreviousName, status.Name) + status.PreviousPath = splitLines[i+1] + status.StatusString = fmt.Sprintf("%s %s -> %s", status.Change, status.PreviousPath, status.Path) i++ } diff --git a/pkg/commands/git_commands/file_loader_test.go b/pkg/commands/git_commands/file_loader_test.go index cc4bbaa07..233bfb855 100644 --- a/pkg/commands/git_commands/file_loader_test.go +++ b/pkg/commands/git_commands/file_loader_test.go @@ -41,7 +41,7 @@ func TestFileGetStatusFiles(t *testing.T) { showNumstatInFilesView: true, expectedFiles: []*models.File{ { - Name: "file1.txt", + Path: "file1.txt", HasStagedChanges: true, HasUnstagedChanges: true, Tracked: true, @@ -55,7 +55,7 @@ func TestFileGetStatusFiles(t *testing.T) { LinesDeleted: 1, }, { - Name: "file3.txt", + Path: "file3.txt", HasStagedChanges: true, HasUnstagedChanges: false, Tracked: false, @@ -69,7 +69,7 @@ func TestFileGetStatusFiles(t *testing.T) { LinesDeleted: 2, }, { - Name: "file2.txt", + Path: "file2.txt", HasStagedChanges: true, HasUnstagedChanges: true, Tracked: false, @@ -83,7 +83,7 @@ func TestFileGetStatusFiles(t *testing.T) { LinesDeleted: 0, }, { - Name: "file4.txt", + Path: "file4.txt", HasStagedChanges: false, HasUnstagedChanges: true, Tracked: false, @@ -97,7 +97,7 @@ func TestFileGetStatusFiles(t *testing.T) { LinesDeleted: 2, }, { - Name: "file5.txt", + Path: "file5.txt", HasStagedChanges: false, HasUnstagedChanges: true, Tracked: true, @@ -119,7 +119,7 @@ func TestFileGetStatusFiles(t *testing.T) { ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"}, "MM a\nb.txt", nil), expectedFiles: []*models.File{ { - Name: "a\nb.txt", + Path: "a\nb.txt", HasStagedChanges: true, HasUnstagedChanges: true, Tracked: true, @@ -142,8 +142,8 @@ func TestFileGetStatusFiles(t *testing.T) { ), expectedFiles: []*models.File{ { - Name: "after1.txt", - PreviousName: "before1.txt", + Path: "after1.txt", + PreviousPath: "before1.txt", HasStagedChanges: true, HasUnstagedChanges: false, Tracked: true, @@ -155,8 +155,8 @@ func TestFileGetStatusFiles(t *testing.T) { ShortStatus: "R ", }, { - Name: "after2.txt", - PreviousName: "before2.txt", + Path: "after2.txt", + PreviousPath: "before2.txt", HasStagedChanges: true, HasUnstagedChanges: true, Tracked: true, @@ -179,7 +179,7 @@ func TestFileGetStatusFiles(t *testing.T) { ), expectedFiles: []*models.File{ { - Name: "a -> b.txt", + Path: "a -> b.txt", HasStagedChanges: false, HasUnstagedChanges: true, Tracked: false, diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 7ed257536..e1339ee56 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -92,11 +92,11 @@ func (self *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) var beforeFile *models.File var afterFile *models.File for _, f := range filesWithoutRenames { - if f.Name == file.PreviousName { + if f.Path == file.PreviousPath { beforeFile = f } - if f.Name == file.Name { + if f.Path == file.Path { afterFile = f } } @@ -134,13 +134,13 @@ func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error if file.ShortStatus == "AA" { if err := self.cmd.New( - NewGitCmd("checkout").Arg("--ours", "--", file.Name).ToArgv(), + NewGitCmd("checkout").Arg("--ours", "--", file.Path).ToArgv(), ).Run(); err != nil { return err } if err := self.cmd.New( - NewGitCmd("add").Arg("--", file.Name).ToArgv(), + NewGitCmd("add").Arg("--", file.Path).ToArgv(), ).Run(); err != nil { return err } @@ -149,14 +149,14 @@ func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error if file.ShortStatus == "DU" { return self.cmd.New( - NewGitCmd("rm").Arg("--", file.Name).ToArgv(), + NewGitCmd("rm").Arg("--", file.Path).ToArgv(), ).Run() } // if the file isn't tracked, we assume you want to delete it if file.HasStagedChanges || file.HasMergeConflicts { if err := self.cmd.New( - NewGitCmd("reset").Arg("--", file.Name).ToArgv(), + NewGitCmd("reset").Arg("--", file.Path).ToArgv(), ).Run(); err != nil { return err } @@ -167,7 +167,7 @@ func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error } if file.Added { - return self.os.RemoveFile(file.Name) + return self.os.RemoveFile(file.Path) } return self.DiscardUnstagedFileChanges(file) @@ -199,7 +199,7 @@ func (self *WorkingTreeCommands) DiscardUnstagedDirChanges(node IFileNode) error } } else { if file.Added && !file.HasStagedChanges { - return self.os.RemoveFile(file.Name) + return self.os.RemoveFile(file.Path) } if err := self.DiscardUnstagedFileChanges(file); err != nil { @@ -226,7 +226,7 @@ func (self *WorkingTreeCommands) RemoveUntrackedDirFiles(node IFileNode) error { } func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error { - cmdArgs := NewGitCmd("checkout").Arg("--", file.Name).ToArgv() + cmdArgs := NewGitCmd("checkout").Arg("--", file.Path).ToArgv() return self.cmd.New(cmdArgs).Run() } diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index fb5463a6d..bbe3d7720 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -83,7 +83,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "An error occurred when resetting", file: &models.File{ - Name: "test", + Path: "test", HasStagedChanges: true, }, removeFile: func(string) error { return nil }, @@ -94,7 +94,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "An error occurred when removing file", file: &models.File{ - Name: "test", + Path: "test", Tracked: false, Added: true, }, @@ -107,7 +107,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "An error occurred with checkout", file: &models.File{ - Name: "test", + Path: "test", Tracked: true, HasStagedChanges: false, }, @@ -119,7 +119,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "Checkout only", file: &models.File{ - Name: "test", + Path: "test", Tracked: true, HasStagedChanges: false, }, @@ -131,7 +131,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "Reset and checkout staged changes", file: &models.File{ - Name: "test", + Path: "test", Tracked: true, HasStagedChanges: true, }, @@ -144,7 +144,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "Reset and checkout merge conflicts", file: &models.File{ - Name: "test", + Path: "test", Tracked: true, HasMergeConflicts: true, }, @@ -157,7 +157,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "Reset and remove", file: &models.File{ - Name: "test", + Path: "test", Tracked: false, Added: true, HasStagedChanges: true, @@ -173,7 +173,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { { testName: "Remove only", file: &models.File{ - Name: "test", + Path: "test", Tracked: false, Added: true, HasStagedChanges: false, @@ -220,7 +220,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "Default case", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: true, }, @@ -235,7 +235,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "cached", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: true, }, @@ -250,7 +250,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "plain", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: true, }, @@ -265,7 +265,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "File not tracked and file has no staged changes", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: false, }, @@ -280,7 +280,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "Default case (ignore whitespace)", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: true, }, @@ -295,7 +295,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "Show diff with custom context size", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: true, }, @@ -310,7 +310,7 @@ func TestWorkingTreeDiff(t *testing.T) { { testName: "Show diff with custom similarity threshold", file: &models.File{ - Name: "test.txt", + Path: "test.txt", HasStagedChanges: false, Tracked: true, }, @@ -466,7 +466,7 @@ func TestWorkingTreeDiscardUnstagedFileChanges(t *testing.T) { scenarios := []scenario{ { testName: "valid case", - file: &models.File{Name: "test.txt"}, + file: &models.File{Path: "test.txt"}, runner: oscommands.NewFakeRunner(t). ExpectGitArgs([]string{"checkout", "--", "test.txt"}, "", nil), test: func(err error) { diff --git a/pkg/commands/models/commit_file.go b/pkg/commands/models/commit_file.go index d05b5b3fd..90ffd6365 100644 --- a/pkg/commands/models/commit_file.go +++ b/pkg/commands/models/commit_file.go @@ -2,18 +2,17 @@ package models // CommitFile : A git commit file type CommitFile struct { - // TODO: rename this to Path - Name string + Path string ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status } func (f *CommitFile) ID() string { - return f.Name + return f.Path } func (f *CommitFile) Description() string { - return f.Name + return f.Path } func (f *CommitFile) Added() bool { @@ -25,5 +24,5 @@ func (f *CommitFile) Deleted() bool { } func (f *CommitFile) GetPath() string { - return f.Name + return f.Path } diff --git a/pkg/commands/models/file.go b/pkg/commands/models/file.go index 4be424e22..561399820 100644 --- a/pkg/commands/models/file.go +++ b/pkg/commands/models/file.go @@ -8,8 +8,8 @@ import ( // File : A file from git status // duplicating this for now type File struct { - Name string - PreviousName string + Path string + PreviousPath string HasStagedChanges bool HasUnstagedChanges bool Tracked bool @@ -37,14 +37,14 @@ type IFile interface { } func (f *File) IsRename() bool { - return f.PreviousName != "" + return f.PreviousPath != "" } // Names returns an array containing just the filename, or in the case of a rename, the after filename and the before filename func (f *File) Names() []string { - result := []string{f.Name} - if f.PreviousName != "" { - result = append(result, f.PreviousName) + result := []string{f.Path} + if f.PreviousPath != "" { + result = append(result, f.PreviousPath) } return result } @@ -55,11 +55,11 @@ func (f *File) Matches(f2 *File) bool { } func (f *File) ID() string { - return f.Name + return f.Path } func (f *File) Description() string { - return f.Name + return f.Path } func (f *File) IsSubmodule(configs []*SubmoduleConfig) bool { @@ -68,7 +68,7 @@ func (f *File) IsSubmodule(configs []*SubmoduleConfig) bool { func (f *File) SubmoduleConfig(configs []*SubmoduleConfig) *SubmoduleConfig { for _, config := range configs { - if f.Name == config.Path { + if f.Path == config.Path { return config } } @@ -90,11 +90,11 @@ func (f *File) GetIsTracked() bool { func (f *File) GetPath() string { // TODO: remove concept of name; just use path - return f.Name + return f.Path } func (f *File) GetPreviousPath() string { - return f.PreviousName + return f.PreviousPath } func (f *File) GetIsFile() bool { diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 69be8ae5d..34bc350ed 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -402,7 +402,7 @@ func (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.Comm // Find if any file in the selection is unselected or partially added adding := lo.SomeBy(selectedNodes, func(node *filetree.CommitFileNode) bool { return node.SomeFile(func(file *models.CommitFile) bool { - fileStatus := self.c.Git().Patch.PatchBuilder.GetFileStatus(file.Name, self.context().GetRef().RefName()) + fileStatus := self.c.Git().Patch.PatchBuilder.GetFileStatus(file.Path, self.context().GetRef().RefName()) return fileStatus == patch.PART || fileStatus == patch.UNSELECTED }) }) @@ -415,7 +415,7 @@ func (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.Comm for _, node := range selectedNodes { err := node.ForEachFile(func(file *models.CommitFile) error { - return patchOperationFunction(file.Name) + return patchOperationFunction(file.Path) }) if err != nil { return err diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 723c16681..e0ee96f81 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -372,7 +372,7 @@ func (self *FilesController) optimisticChange(nodes []*filetree.FileNode, optimi err := node.ForEachFile(func(f *models.File) error { // can't act on the file itself: we need to update the original model file for _, modelFile := range self.c.Model().Files { - if modelFile.Name == f.Name { + if modelFile.Path == f.Path { if optimisticChangeFn(modelFile) { rerender = true } @@ -897,7 +897,7 @@ func (self *FilesController) switchToMerge() error { return nil } - return self.c.Helpers().MergeConflicts.SwitchToMerge(file.Name) + return self.c.Helpers().MergeConflicts.SwitchToMerge(file.Path) } func (self *FilesController) createStashMenu() error { diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index e267f8360..33347a363 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -554,11 +554,11 @@ func (self *RefreshHelper) refreshStateFiles() error { prevConflictFileCount++ } if file.HasInlineMergeConflicts { - hasConflicts, err := mergeconflicts.FileHasConflictMarkers(file.Name) + hasConflicts, err := mergeconflicts.FileHasConflictMarkers(file.Path) if err != nil { self.c.Log.Error(err) } else if !hasConflicts { - pathsToStage = append(pathsToStage, file.Name) + pathsToStage = append(pathsToStage, file.Path) } } } diff --git a/pkg/gui/filetree/build_tree.go b/pkg/gui/filetree/build_tree.go index 0193ba45c..b948b4c43 100644 --- a/pkg/gui/filetree/build_tree.go +++ b/pkg/gui/filetree/build_tree.go @@ -14,7 +14,7 @@ func BuildTreeFromFiles(files []*models.File) *Node[models.File] { var curr *Node[models.File] for _, file := range files { - splitPath := split(file.Name) + splitPath := split(file.Path) curr = root outer: for i := range splitPath { @@ -70,7 +70,7 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *Node[models.CommitFil var curr *Node[models.CommitFile] for _, file := range files { - splitPath := split(file.Name) + splitPath := split(file.Path) curr = root outer: for i := range splitPath { diff --git a/pkg/gui/filetree/build_tree_test.go b/pkg/gui/filetree/build_tree_test.go index eab8babc2..5180617f9 100644 --- a/pkg/gui/filetree/build_tree_test.go +++ b/pkg/gui/filetree/build_tree_test.go @@ -25,10 +25,10 @@ func TestBuildTreeFromFiles(t *testing.T) { name: "files in same directory", files: []*models.File{ { - Name: "dir1/a", + Path: "dir1/a", }, { - Name: "dir1/b", + Path: "dir1/b", }, }, expected: &Node[models.File]{ @@ -38,11 +38,11 @@ func TestBuildTreeFromFiles(t *testing.T) { Path: "dir1", Children: []*Node[models.File]{ { - File: &models.File{Name: "dir1/a"}, + File: &models.File{Path: "dir1/a"}, Path: "dir1/a", }, { - File: &models.File{Name: "dir1/b"}, + File: &models.File{Path: "dir1/b"}, Path: "dir1/b", }, }, @@ -54,10 +54,10 @@ func TestBuildTreeFromFiles(t *testing.T) { name: "paths that can be compressed", files: []*models.File{ { - Name: "dir1/dir3/a", + Path: "dir1/dir3/a", }, { - Name: "dir2/dir4/b", + Path: "dir2/dir4/b", }, }, expected: &Node[models.File]{ @@ -67,7 +67,7 @@ func TestBuildTreeFromFiles(t *testing.T) { Path: "dir1/dir3", Children: []*Node[models.File]{ { - File: &models.File{Name: "dir1/dir3/a"}, + File: &models.File{Path: "dir1/dir3/a"}, Path: "dir1/dir3/a", }, }, @@ -77,7 +77,7 @@ func TestBuildTreeFromFiles(t *testing.T) { Path: "dir2/dir4", Children: []*Node[models.File]{ { - File: &models.File{Name: "dir2/dir4/b"}, + File: &models.File{Path: "dir2/dir4/b"}, Path: "dir2/dir4/b", }, }, @@ -90,21 +90,21 @@ func TestBuildTreeFromFiles(t *testing.T) { name: "paths that can be sorted", files: []*models.File{ { - Name: "b", + Path: "b", }, { - Name: "a", + Path: "a", }, }, expected: &Node[models.File]{ Path: "", Children: []*Node[models.File]{ { - File: &models.File{Name: "a"}, + File: &models.File{Path: "a"}, Path: "a", }, { - File: &models.File{Name: "b"}, + File: &models.File{Path: "b"}, Path: "b", }, }, @@ -114,14 +114,14 @@ func TestBuildTreeFromFiles(t *testing.T) { name: "paths that can be sorted including a merge conflict file", files: []*models.File{ { - Name: "b", + Path: "b", }, { - Name: "z", + Path: "z", HasMergeConflicts: true, }, { - Name: "a", + Path: "a", }, }, expected: &Node[models.File]{ @@ -130,15 +130,15 @@ func TestBuildTreeFromFiles(t *testing.T) { // here but we are technically still in tree mode and that's the rule Children: []*Node[models.File]{ { - File: &models.File{Name: "a"}, + File: &models.File{Path: "a"}, Path: "a", }, { - File: &models.File{Name: "b"}, + File: &models.File{Path: "b"}, Path: "b", }, { - File: &models.File{Name: "z", HasMergeConflicts: true}, + File: &models.File{Path: "z", HasMergeConflicts: true}, Path: "z", }, }, @@ -172,22 +172,22 @@ func TestBuildFlatTreeFromFiles(t *testing.T) { name: "files in same directory", files: []*models.File{ { - Name: "dir1/a", + Path: "dir1/a", }, { - Name: "dir1/b", + Path: "dir1/b", }, }, expected: &Node[models.File]{ Path: "", Children: []*Node[models.File]{ { - File: &models.File{Name: "dir1/a"}, + File: &models.File{Path: "dir1/a"}, Path: "dir1/a", CompressionLevel: 0, }, { - File: &models.File{Name: "dir1/b"}, + File: &models.File{Path: "dir1/b"}, Path: "dir1/b", CompressionLevel: 0, }, @@ -198,22 +198,22 @@ func TestBuildFlatTreeFromFiles(t *testing.T) { name: "paths that can be compressed", files: []*models.File{ { - Name: "dir1/a", + Path: "dir1/a", }, { - Name: "dir2/b", + Path: "dir2/b", }, }, expected: &Node[models.File]{ Path: "", Children: []*Node[models.File]{ { - File: &models.File{Name: "dir1/a"}, + File: &models.File{Path: "dir1/a"}, Path: "dir1/a", CompressionLevel: 0, }, { - File: &models.File{Name: "dir2/b"}, + File: &models.File{Path: "dir2/b"}, Path: "dir2/b", CompressionLevel: 0, }, @@ -224,21 +224,21 @@ func TestBuildFlatTreeFromFiles(t *testing.T) { name: "paths that can be sorted", files: []*models.File{ { - Name: "b", + Path: "b", }, { - Name: "a", + Path: "a", }, }, expected: &Node[models.File]{ Path: "", Children: []*Node[models.File]{ { - File: &models.File{Name: "a"}, + File: &models.File{Path: "a"}, Path: "a", }, { - File: &models.File{Name: "b"}, + File: &models.File{Path: "b"}, Path: "b", }, }, @@ -248,27 +248,27 @@ func TestBuildFlatTreeFromFiles(t *testing.T) { name: "tracked, untracked, and conflicted files", files: []*models.File{ { - Name: "a2", + Path: "a2", Tracked: false, }, { - Name: "a1", + Path: "a1", Tracked: false, }, { - Name: "c2", + Path: "c2", HasMergeConflicts: true, }, { - Name: "c1", + Path: "c1", HasMergeConflicts: true, }, { - Name: "b2", + Path: "b2", Tracked: true, }, { - Name: "b1", + Path: "b1", Tracked: true, }, }, @@ -276,27 +276,27 @@ func TestBuildFlatTreeFromFiles(t *testing.T) { Path: "", Children: []*Node[models.File]{ { - File: &models.File{Name: "c1", HasMergeConflicts: true}, + File: &models.File{Path: "c1", HasMergeConflicts: true}, Path: "c1", }, { - File: &models.File{Name: "c2", HasMergeConflicts: true}, + File: &models.File{Path: "c2", HasMergeConflicts: true}, Path: "c2", }, { - File: &models.File{Name: "b1", Tracked: true}, + File: &models.File{Path: "b1", Tracked: true}, Path: "b1", }, { - File: &models.File{Name: "b2", Tracked: true}, + File: &models.File{Path: "b2", Tracked: true}, Path: "b2", }, { - File: &models.File{Name: "a1", Tracked: false}, + File: &models.File{Path: "a1", Tracked: false}, Path: "a1", }, { - File: &models.File{Name: "a2", Tracked: false}, + File: &models.File{Path: "a2", Tracked: false}, Path: "a2", }, }, @@ -330,10 +330,10 @@ func TestBuildTreeFromCommitFiles(t *testing.T) { name: "files in same directory", files: []*models.CommitFile{ { - Name: "dir1/a", + Path: "dir1/a", }, { - Name: "dir1/b", + Path: "dir1/b", }, }, expected: &Node[models.CommitFile]{ @@ -343,11 +343,11 @@ func TestBuildTreeFromCommitFiles(t *testing.T) { Path: "dir1", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "dir1/a"}, + File: &models.CommitFile{Path: "dir1/a"}, Path: "dir1/a", }, { - File: &models.CommitFile{Name: "dir1/b"}, + File: &models.CommitFile{Path: "dir1/b"}, Path: "dir1/b", }, }, @@ -359,10 +359,10 @@ func TestBuildTreeFromCommitFiles(t *testing.T) { name: "paths that can be compressed", files: []*models.CommitFile{ { - Name: "dir1/dir3/a", + Path: "dir1/dir3/a", }, { - Name: "dir2/dir4/b", + Path: "dir2/dir4/b", }, }, expected: &Node[models.CommitFile]{ @@ -372,7 +372,7 @@ func TestBuildTreeFromCommitFiles(t *testing.T) { Path: "dir1/dir3", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "dir1/dir3/a"}, + File: &models.CommitFile{Path: "dir1/dir3/a"}, Path: "dir1/dir3/a", }, }, @@ -382,7 +382,7 @@ func TestBuildTreeFromCommitFiles(t *testing.T) { Path: "dir2/dir4", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "dir2/dir4/b"}, + File: &models.CommitFile{Path: "dir2/dir4/b"}, Path: "dir2/dir4/b", }, }, @@ -395,21 +395,21 @@ func TestBuildTreeFromCommitFiles(t *testing.T) { name: "paths that can be sorted", files: []*models.CommitFile{ { - Name: "b", + Path: "b", }, { - Name: "a", + Path: "a", }, }, expected: &Node[models.CommitFile]{ Path: "", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "a"}, + File: &models.CommitFile{Path: "a"}, Path: "a", }, { - File: &models.CommitFile{Name: "b"}, + File: &models.CommitFile{Path: "b"}, Path: "b", }, }, @@ -443,22 +443,22 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) { name: "files in same directory", files: []*models.CommitFile{ { - Name: "dir1/a", + Path: "dir1/a", }, { - Name: "dir1/b", + Path: "dir1/b", }, }, expected: &Node[models.CommitFile]{ Path: "", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "dir1/a"}, + File: &models.CommitFile{Path: "dir1/a"}, Path: "dir1/a", CompressionLevel: 0, }, { - File: &models.CommitFile{Name: "dir1/b"}, + File: &models.CommitFile{Path: "dir1/b"}, Path: "dir1/b", CompressionLevel: 0, }, @@ -469,22 +469,22 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) { name: "paths that can be compressed", files: []*models.CommitFile{ { - Name: "dir1/a", + Path: "dir1/a", }, { - Name: "dir2/b", + Path: "dir2/b", }, }, expected: &Node[models.CommitFile]{ Path: "", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "dir1/a"}, + File: &models.CommitFile{Path: "dir1/a"}, Path: "dir1/a", CompressionLevel: 0, }, { - File: &models.CommitFile{Name: "dir2/b"}, + File: &models.CommitFile{Path: "dir2/b"}, Path: "dir2/b", CompressionLevel: 0, }, @@ -495,21 +495,21 @@ func TestBuildFlatTreeFromCommitFiles(t *testing.T) { name: "paths that can be sorted", files: []*models.CommitFile{ { - Name: "b", + Path: "b", }, { - Name: "a", + Path: "a", }, }, expected: &Node[models.CommitFile]{ Path: "", Children: []*Node[models.CommitFile]{ { - File: &models.CommitFile{Name: "a"}, + File: &models.CommitFile{Path: "a"}, Path: "a", }, { - File: &models.CommitFile{Name: "b"}, + File: &models.CommitFile{Path: "b"}, Path: "b", }, }, diff --git a/pkg/gui/filetree/commit_file_tree.go b/pkg/gui/filetree/commit_file_tree.go index 9c8e0bf52..008033b6a 100644 --- a/pkg/gui/filetree/commit_file_tree.go +++ b/pkg/gui/filetree/commit_file_tree.go @@ -119,7 +119,7 @@ func (self *CommitFileTree) CollapsedPaths() *CollapsedPaths { func (self *CommitFileTree) GetFile(path string) *models.CommitFile { for _, file := range self.getFiles() { - if file.Name == path { + if file.Path == path { return file } } diff --git a/pkg/gui/filetree/file_node.go b/pkg/gui/filetree/file_node.go index d55bc56aa..0836eaf02 100644 --- a/pkg/gui/filetree/file_node.go +++ b/pkg/gui/filetree/file_node.go @@ -51,7 +51,7 @@ func (self *FileNode) GetHasInlineMergeConflicts() bool { if !file.HasInlineMergeConflicts { return false } - hasConflicts, _ := mergeconflicts.FileHasConflictMarkers(file.Name) + hasConflicts, _ := mergeconflicts.FileHasConflictMarkers(file.Path) return hasConflicts }) } @@ -69,5 +69,5 @@ func (self *FileNode) GetPreviousPath() string { return "" } - return self.File.PreviousName + return self.File.PreviousPath } diff --git a/pkg/gui/filetree/file_node_test.go b/pkg/gui/filetree/file_node_test.go index c32f0e666..ddb72e038 100644 --- a/pkg/gui/filetree/file_node_test.go +++ b/pkg/gui/filetree/file_node_test.go @@ -23,13 +23,13 @@ func TestCompress(t *testing.T) { root: &Node[models.File]{ Path: "", Children: []*Node[models.File]{ - {File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"}, + {File: &models.File{Path: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"}, }, }, expected: &Node[models.File]{ Path: "", Children: []*Node[models.File]{ - {File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"}, + {File: &models.File{Path: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"}, }, }, }, @@ -42,7 +42,7 @@ func TestCompress(t *testing.T) { Path: "dir1", Children: []*Node[models.File]{ { - File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir1/file2", }, }, @@ -51,11 +51,11 @@ func TestCompress(t *testing.T) { Path: "dir2", Children: []*Node[models.File]{ { - File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, + File: &models.File{Path: "file3", ShortStatus: " M", HasStagedChanges: true}, Path: "dir2/file3", }, { - File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file4", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir2/file4", }, }, @@ -67,7 +67,7 @@ func TestCompress(t *testing.T) { Path: "dir3/dir3-1", Children: []*Node[models.File]{ { - File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir3/dir3-1/file5", }, }, @@ -75,7 +75,7 @@ func TestCompress(t *testing.T) { }, }, { - File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "file1", }, }, @@ -87,7 +87,7 @@ func TestCompress(t *testing.T) { Path: "dir1", Children: []*Node[models.File]{ { - File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir1/file2", }, }, @@ -96,11 +96,11 @@ func TestCompress(t *testing.T) { Path: "dir2", Children: []*Node[models.File]{ { - File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, + File: &models.File{Path: "file3", ShortStatus: " M", HasStagedChanges: true}, Path: "dir2/file3", }, { - File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file4", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir2/file4", }, }, @@ -110,13 +110,13 @@ func TestCompress(t *testing.T) { CompressionLevel: 1, Children: []*Node[models.File]{ { - File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir3/dir3-1/file5", }, }, }, { - File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + File: &models.File{Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "file1", }, }, @@ -141,13 +141,13 @@ func TestGetFile(t *testing.T) { }{ { name: "valid case", - viewModel: NewFileTree(func() []*models.File { return []*models.File{{Name: "blah/one"}, {Name: "blah/two"}} }, nil, false), + viewModel: NewFileTree(func() []*models.File { return []*models.File{{Path: "blah/one"}, {Path: "blah/two"}} }, nil, false), path: "blah/two", - expected: &models.File{Name: "blah/two"}, + expected: &models.File{Path: "blah/two"}, }, { name: "not found", - viewModel: NewFileTree(func() []*models.File { return []*models.File{{Name: "blah/one"}, {Name: "blah/two"}} }, nil, false), + viewModel: NewFileTree(func() []*models.File { return []*models.File{{Path: "blah/one"}, {Path: "blah/two"}} }, nil, false), path: "blah/three", expected: nil, }, diff --git a/pkg/gui/filetree/file_tree.go b/pkg/gui/filetree/file_tree.go index fe18db0c0..04d92ba35 100644 --- a/pkg/gui/filetree/file_tree.go +++ b/pkg/gui/filetree/file_tree.go @@ -125,7 +125,7 @@ func (self *FileTree) Get(index int) *FileNode { func (self *FileTree) GetFile(path string) *models.File { for _, file := range self.getFiles() { - if file.Name == path { + if file.Path == path { return file } } diff --git a/pkg/gui/filetree/file_tree_test.go b/pkg/gui/filetree/file_tree_test.go index a3cdfd966..4a593711c 100644 --- a/pkg/gui/filetree/file_tree_test.go +++ b/pkg/gui/filetree/file_tree_test.go @@ -18,67 +18,67 @@ func TestFilterAction(t *testing.T) { name: "filter files with unstaged changes", filter: DisplayUnstaged, files: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir2/file5", ShortStatus: "M ", HasStagedChanges: true}, - {Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/file5", ShortStatus: "M ", HasStagedChanges: true}, + {Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, }, expected: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, }, }, { name: "filter files with staged changes", filter: DisplayStaged, files: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true}, - {Name: "dir2/file5", ShortStatus: "M ", HasStagedChanges: false}, - {Name: "file1", ShortStatus: "M ", HasStagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true}, + {Path: "dir2/file5", ShortStatus: "M ", HasStagedChanges: false}, + {Path: "file1", ShortStatus: "M ", HasStagedChanges: true}, }, expected: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true}, - {Name: "file1", ShortStatus: "M ", HasStagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true}, + {Path: "file1", ShortStatus: "M ", HasStagedChanges: true}, }, }, { name: "filter files that are tracked", filter: DisplayTracked, files: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", Tracked: true}, - {Name: "dir2/file5", ShortStatus: "M ", Tracked: false}, - {Name: "file1", ShortStatus: "M ", Tracked: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", Tracked: true}, + {Path: "dir2/file5", ShortStatus: "M ", Tracked: false}, + {Path: "file1", ShortStatus: "M ", Tracked: true}, }, expected: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", Tracked: true}, - {Name: "file1", ShortStatus: "M ", Tracked: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", Tracked: true}, + {Path: "file1", ShortStatus: "M ", Tracked: true}, }, }, { name: "filter all files", filter: DisplayAll, files: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, }, expected: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, }, }, { name: "filter conflicted files", filter: DisplayConflicted, files: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "DU", HasMergeConflicts: true}, - {Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir2/file6", ShortStatus: " M", HasStagedChanges: true}, - {Name: "file1", ShortStatus: "UU", HasMergeConflicts: true, HasInlineMergeConflicts: true}, + {Path: "dir2/dir2/file4", ShortStatus: "DU", HasMergeConflicts: true}, + {Path: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/file6", ShortStatus: " M", HasStagedChanges: true}, + {Path: "file1", ShortStatus: "UU", HasMergeConflicts: true, HasInlineMergeConflicts: true}, }, expected: []*models.File{ - {Name: "dir2/dir2/file4", ShortStatus: "DU", HasMergeConflicts: true}, - {Name: "file1", ShortStatus: "UU", HasMergeConflicts: true, HasInlineMergeConflicts: true}, + {Path: "dir2/dir2/file4", ShortStatus: "DU", HasMergeConflicts: true}, + {Path: "file1", ShortStatus: "UU", HasMergeConflicts: true, HasInlineMergeConflicts: true}, }, }, } diff --git a/pkg/gui/filetree/file_tree_view_model.go b/pkg/gui/filetree/file_tree_view_model.go index 29f563834..307cd05ea 100644 --- a/pkg/gui/filetree/file_tree_view_model.go +++ b/pkg/gui/filetree/file_tree_view_model.go @@ -103,8 +103,8 @@ func (self *FileTreeViewModel) SetTree() { // for when you stage the old file of a rename and the new file is in a collapsed dir for _, file := range newFiles { - if selectedNode != nil && selectedNode.Path != "" && file.PreviousName == selectedNode.Path { - self.ExpandToPath(file.Name) + if selectedNode != nil && selectedNode.Path != "" && file.PreviousPath == selectedNode.Path { + self.ExpandToPath(file.Path) } } @@ -151,7 +151,7 @@ func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNod // If you started off with a rename selected, and now it's broken in two, we want you to jump to the new file, not the old file. // This is because the new should be in the same position as the rename was meaning less cursor jumping - foundOldFileInRename := prevNode.File != nil && prevNode.File.IsRename() && node.Path == prevNode.File.PreviousName + foundOldFileInRename := prevNode.File != nil && prevNode.File.IsRename() && node.Path == prevNode.File.PreviousPath foundNode := utils.StringArraysOverlap(paths, selectedPaths) && !foundOldFileInRename if foundNode { return idx diff --git a/pkg/gui/presentation/files.go b/pkg/gui/presentation/files.go index b3123fe32..0641c4cbf 100644 --- a/pkg/gui/presentation/files.go +++ b/pkg/gui/presentation/files.go @@ -52,11 +52,11 @@ func commitFilePatchStatus(node *filetree.Node[models.CommitFile], tree *filetre // be whatever status it is, but if it's a non-leaf it will determine its status // based on the leaves of that subtree if node.EveryFile(func(file *models.CommitFile) bool { - return patchBuilder.GetFileStatus(file.Name, tree.GetRef().RefName()) == patch.WHOLE + return patchBuilder.GetFileStatus(file.Path, tree.GetRef().RefName()) == patch.WHOLE }) { return patch.WHOLE } else if node.EveryFile(func(file *models.CommitFile) bool { - return patchBuilder.GetFileStatus(file.Name, tree.GetRef().RefName()) == patch.UNSELECTED + return patchBuilder.GetFileStatus(file.Path, tree.GetRef().RefName()) == patch.UNSELECTED }) { return patch.UNSELECTED } else { @@ -297,9 +297,9 @@ func fileNameAtDepth(node *filetree.Node[models.File], depth int) string { name := join(splitName[depth:]) if node.File != nil && node.File.IsRename() { - splitPrevName := split(node.File.PreviousName) + splitPrevName := split(node.File.PreviousPath) - prevName := node.File.PreviousName + prevName := node.File.PreviousPath // if the file has just been renamed inside the same directory, we can shave off // the prefix for the previous path too. Otherwise we'll keep it unchanged sameParentDir := len(splitName) == len(splitPrevName) && join(splitName[0:depth]) == join(splitPrevName[0:depth]) diff --git a/pkg/gui/presentation/files_test.go b/pkg/gui/presentation/files_test.go index a6cdbf99d..5427d0c07 100644 --- a/pkg/gui/presentation/files_test.go +++ b/pkg/gui/presentation/files_test.go @@ -34,17 +34,17 @@ func TestRenderFileTree(t *testing.T) { { name: "leaf node", files: []*models.File{ - {Name: "test", ShortStatus: " M", HasStagedChanges: true}, + {Path: "test", ShortStatus: " M", HasStagedChanges: true}, }, expected: []string{" M test"}, }, { name: "numstat", files: []*models.File{ - {Name: "test", ShortStatus: " M", HasStagedChanges: true, LinesAdded: 1, LinesDeleted: 1}, - {Name: "test2", ShortStatus: " M", HasStagedChanges: true, LinesAdded: 1}, - {Name: "test3", ShortStatus: " M", HasStagedChanges: true, LinesDeleted: 1}, - {Name: "test4", ShortStatus: " M", HasStagedChanges: true, LinesAdded: 0, LinesDeleted: 0}, + {Path: "test", ShortStatus: " M", HasStagedChanges: true, LinesAdded: 1, LinesDeleted: 1}, + {Path: "test2", ShortStatus: " M", HasStagedChanges: true, LinesAdded: 1}, + {Path: "test3", ShortStatus: " M", HasStagedChanges: true, LinesDeleted: 1}, + {Path: "test4", ShortStatus: " M", HasStagedChanges: true, LinesAdded: 0, LinesDeleted: 0}, }, showLineChanges: true, expected: []string{ @@ -57,12 +57,12 @@ func TestRenderFileTree(t *testing.T) { { name: "big example", files: []*models.File{ - {Name: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir1/file3", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir2/dir2/file3", ShortStatus: " M", HasStagedChanges: true}, - {Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, - {Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir1/file3", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/dir2/file3", ShortStatus: " M", HasStagedChanges: true}, + {Path: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, + {Path: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, }, expected: toStringSlice( ` @@ -111,19 +111,19 @@ func TestRenderCommitFileTree(t *testing.T) { { name: "leaf node", files: []*models.CommitFile{ - {Name: "test", ChangeStatus: "A"}, + {Path: "test", ChangeStatus: "A"}, }, expected: []string{"A test"}, }, { name: "big example", files: []*models.CommitFile{ - {Name: "dir1/file2", ChangeStatus: "M"}, - {Name: "dir1/file3", ChangeStatus: "A"}, - {Name: "dir2/dir2/file3", ChangeStatus: "D"}, - {Name: "dir2/dir2/file4", ChangeStatus: "M"}, - {Name: "dir2/file5", ChangeStatus: "M"}, - {Name: "file1", ChangeStatus: "M"}, + {Path: "dir1/file2", ChangeStatus: "M"}, + {Path: "dir1/file3", ChangeStatus: "A"}, + {Path: "dir2/dir2/file3", ChangeStatus: "D"}, + {Path: "dir2/dir2/file4", ChangeStatus: "M"}, + {Path: "dir2/file5", ChangeStatus: "M"}, + {Path: "file1", ChangeStatus: "M"}, }, expected: toStringSlice( ` diff --git a/pkg/gui/services/custom_commands/session_state_loader.go b/pkg/gui/services/custom_commands/session_state_loader.go index 8d6ef5b48..933a99711 100644 --- a/pkg/gui/services/custom_commands/session_state_loader.go +++ b/pkg/gui/services/custom_commands/session_state_loader.go @@ -47,8 +47,8 @@ func fileShimFromModelFile(file *models.File) *File { } return &File{ - Name: file.Name, - PreviousName: file.PreviousName, + Name: file.Path, + PreviousName: file.PreviousPath, HasStagedChanges: file.HasStagedChanges, HasUnstagedChanges: file.HasUnstagedChanges, Tracked: file.Tracked, @@ -141,7 +141,7 @@ func commitFileShimFromModelRemote(commitFile *models.CommitFile) *CommitFile { } return &CommitFile{ - Name: commitFile.Name, + Name: commitFile.Path, ChangeStatus: commitFile.ChangeStatus, } }