Skip to content

Commit 60a7d6a

Browse files
authored
Fix normalisedSelectedNodes function (#4920)
The `normalisedSelectedNodes` function in `files_controller.go` had a bug where it didn't work correctly for the root item (`/`). This PR fixes that. We don't have any tests for this bug. Apparently, the functions that use this (staging and discarding files) also work correctly when they work on a directory and then on the contained file again, that's why nobody has noticed yet. I briefly looked into adding unit tests for the function, but it was more work than I was willing to put into this right now.
2 parents 6478bf4 + 302b621 commit 60a7d6a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/gui/controllers/files_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,14 @@ func normalisedSelectedNodes(selectedNodes []*filetree.FileNode) []*filetree.Fil
12211221
}
12221222

12231223
func isDescendentOfSelectedNodes(node *filetree.FileNode, selectedNodes []*filetree.FileNode) bool {
1224+
nodePath := node.GetInternalPath()
1225+
12241226
for _, selectedNode := range selectedNodes {
12251227
if selectedNode.IsFile() {
12261228
continue
12271229
}
12281230

1229-
selectedNodePath := selectedNode.GetPath()
1230-
nodePath := node.GetPath()
1231+
selectedNodePath := selectedNode.GetInternalPath()
12311232

12321233
if strings.HasPrefix(nodePath, selectedNodePath+"/") {
12331234
return true

0 commit comments

Comments
 (0)