Repository navigation
fix(file_tree): keep file and directory nodes with the same name apart - #380
Open
rainerborene wants to merge 1 commit into
Open
rainerborene wants to merge 1 commit into
rainerborene wants to merge 1 commit into
Conversation
A diff can contain both a path and entries below it, e.g. when a
directory is replaced by a symlink while the files it used to contain
are deleted in the same change:
A .claude/commands
D .claude/commands/commit.md
`FileTree:add_file_entry()` looked intermediate directories up by name
only, so the `commands` file node was reused as the parent of
`commit.md`. The renderer then received a `FileEntry` where it expected
`DirData`, and `ctx.name` resolved to the inherited `Object:name()`
class method:
render.lua:36: attempt to concatenate local 'name' (a function value)
Give `Node` a lookup key separate from its display name and key
directory nodes with a trailing separator, so a file and a directory of
the same name can coexist under one parent. Sorting and rendering keep
using `name`, so the panel output is unchanged for existing trees.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
:DiffviewOpencrashes when the diff contains both a path and entries below it. The common way to hit this is replacing a directory with a symlink while the files it used to contain are deleted in the same change:Same root cause as upstream sindrets#523 ("Diffview cannot be shown when file is changed into folder").
Cause
FileTree:add_file_entry()looks intermediate directories up innode.childrenby name only. When thecommandsfile entry is added first, the latercommands/commit.mdentry reuses that file node as its parent. The renderer then receives aFileEntrywhere it expectsDirData, andctx.nameresolves to the inheritedObject:name()class method instead of a string. With the opposite insertion order the file entry is silently dropped instead.Fix
Nodegets akeyfield used for sibling lookup inadd_child(). It defaults toname, so existing callers are unaffected.FileTreekeys directory nodes asname .. "/". A path component can never contain the separator, so a file and a directory of the same name can now coexist under one parent.nameandpath, so output for existing trees is unchanged.Tests
New
file_tree_spec.luacovers both insertion orders: the tree keeps a separate leaf and directory node,create_comp_schema()yields string names for every directory context, statuses are derived from children only, andflatten_dirsstill behaves. It also pins the defaultkey == namebehaviour and the existing directory dedup.Locally:
make testpasses apart from thehg_*/jj_*specs, which fail identically onmainhere because those binaries are not installed.stylua --checkandmake type-checkare clean.Verified against the real repo that triggered the crash. The panel now shows the
commands/folder with its deleted file and the newcommandssymlink side by side: