Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change field name of CommitFile #3515

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/commit_file_loader.go
Expand Up @@ -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],
}
})
}
12 changes: 6 additions & 6 deletions pkg/commands/git_commands/commit_file_loader_test.go
Expand Up @@ -23,7 +23,7 @@ func TestGetCommitFilesFromFilenames(t *testing.T) {
input: "MM\x00Myfile\x00",
output: []*models.CommitFile{
{
Name: "Myfile",
Path: "Myfile",
ChangeStatus: "MM",
},
},
Expand All @@ -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 ",
},
},
Expand All @@ -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",
},
},
Expand Down
9 changes: 4 additions & 5 deletions pkg/commands/models/commit_file.go
Expand Up @@ -2,18 +2,17 @@ package models

// CommitFile : A git commit file
type CommitFile struct {
// TODO: rename this to Path
Name string
Path string // e.g. '/path/to/mydir'

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 {
Expand All @@ -25,5 +24,5 @@ func (f *CommitFile) Deleted() bool {
}

func (f *CommitFile) GetPath() string {
return f.Name
return f.Path
}
4 changes: 2 additions & 2 deletions pkg/gui/controllers/commits_files_controller.go
Expand Up @@ -279,7 +279,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
})
})
Expand All @@ -292,7 +292,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
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/filetree/build_tree.go
Expand Up @@ -58,7 +58,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 {
Expand Down
48 changes: 24 additions & 24 deletions pkg/gui/filetree/build_tree_test.go
Expand Up @@ -332,10 +332,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]{
Expand All @@ -345,11 +345,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",
},
},
Expand All @@ -361,10 +361,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]{
Expand All @@ -374,7 +374,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",
},
},
Expand All @@ -384,7 +384,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",
},
},
Expand All @@ -397,21 +397,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",
},
},
Expand Down Expand Up @@ -446,22 +446,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,
},
Expand All @@ -472,22 +472,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,
},
Expand All @@ -498,21 +498,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",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/filetree/commit_file_tree.go
Expand Up @@ -105,7 +105,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
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/presentation/files.go
Expand Up @@ -51,11 +51,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 {
Expand Down
14 changes: 7 additions & 7 deletions pkg/gui/presentation/files_test.go
Expand Up @@ -95,19 +95,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(
`
Expand Down