fix(filetree): use forward-slash path separator for git diff paths (#121)#128
Merged
dlvhdr merged 1 commit intoMay 2, 2026
Merged
Conversation
…lvhdr#121) git diff always emits forward-slash paths regardless of host OS. The file tree builder used os.PathSeparator and filepath.Dir/Join, which on Windows split paths on '\'. Since git paths contain only '/', no split ever happened and every file became a flat root child with no directory hierarchy. Reported by @abdmoh123 in dlvhdr#121: tree shows files as a list, not a tree, on native Windows. Linux and WSL were unaffected because their os.PathSeparator is already '/'. Switch to the path package (forward-slash, OS-agnostic) for all git-path manipulation in buildFullFileTree and collapseTree. Six call sites updated; imports trimmed (os and path/filepath dropped, path added). Verification: - Pre-fix Windows (Go 1.26.2 native): TestBuildFullFileTree fails with "expected 5 nodes, but got 3" (the bug abdmoh123 reported). - Post-fix Windows: full test suite passes. - Pre-fix Linux (golang:1.26 container): all tests pass; Linux is not affected by the bug because os.PathSeparator is already '/'. - Post-fix Linux: all tests still pass; behavior is byte-for-byte identical because path.{Dir,Join} return the same results as filepath.{Dir,Join} when inputs are forward-slash. The existing TestBuildFullFileTree, TestCollapseTree, TestUncollapsableTree, and TestCloseDirsBelow* serve as the regression tests; the fix flips them from failing to passing on Windows without disturbing Linux behavior.
dlvhdr
approved these changes
May 2, 2026
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.
Closes #121.
What this fixes
On native Windows, the file tree pane shows every file as a flat list at the root level — no directory hierarchy is rendered. Reported by @abdmoh123 in #121, with the symptom verified on multiple Windows machines and confirmed working on Linux + WSL.
Root cause
buildFullFileTree(andcollapseTree) split and join paths usingos.PathSeparatorandfilepath.{Dir,Join}.git diffalways emits forward-slash paths regardless of host OS, but on Windowsos.PathSeparator == '\'. So:Every file gets walked as a single path component, never matches an existing directory in the tree, and ends up as a top-level file child of the root. Hence the flat list @abdmoh123 saw.
Fix
Swap to the
pathpackage (forward-slash, OS-agnostic) for everything that handles git-supplied paths. Six call sites changed inpkg/ui/panes/filetree/filetree.go:filepath.Dir(name)path.Dir(name)string(os.PathSeparator)(×3)"/"filepath.Join(...)(×3)path.Join(...)Imports trimmed: drop
"os"and"path/filepath", add"path". Net: +13 / −9 lines, single file.Verification
Empirically tested both platforms before opening this PR — the existing test suite is the regression test:
TestBuildFullFileTreefails: expected 5 nodes, but got 3golang:1.26Docker container)Linux behavior is unchanged because
os.PathSeparator == '/'on Linux already, andpath.{Dir,Join}produce identical output tofilepath.{Dir,Join}for forward-slash inputs. The fix only affects Windows code paths where the previous behavior was already broken.TestBuildFullFileTree,TestCollapseTree,TestUncollapsableTree, andTestCloseDirsBelowDepth*all flip from failing to passing on Windows under the fix; no new tests were needed.Side benefits beyond the file-tree rendering
DirNode.FullPathis also used to:SetCursorByPath(filetree.go:188) — used for cursor positioning. Pre-fix on Windows, paths stored as"a\b"would never match git-supplied"a/b". Post-fix, they match.SetDirPatchintui.go:1349— the dir-patch viewer for browsing all changes under a directory. Same fix applies.CurrNodePath. Post-fix, copied paths use/everywhere, which is what users will paste back into git commands regardless of host OS.So the fix incidentally repairs cursor positioning and the dir-patch view on Windows alongside the visible tree rendering.
Credit
Original report and reproduction across multiple Windows machines and config states by @abdmoh123 in #121. They isolated it to native Windows (Linux and WSL work fine), tested with multiple terminal emulators, and confirmed the issue reproduces with default config — saving a lot of triage work.