Skip to content

fix(filetree): use forward-slash path separator for git diff paths (#121)#128

Merged
dlvhdr merged 1 commit into
dlvhdr:mainfrom
Booyaka101:fix/file-tree-windows-path-separator
May 2, 2026
Merged

fix(filetree): use forward-slash path separator for git diff paths (#121)#128
dlvhdr merged 1 commit into
dlvhdr:mainfrom
Booyaka101:fix/file-tree-windows-path-separator

Conversation

@Booyaka101
Copy link
Copy Markdown
Contributor

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 (and collapseTree) split and join paths using os.PathSeparator and filepath.{Dir,Join}. git diff always emits forward-slash paths regardless of host OS, but on Windows os.PathSeparator == '\'. So:

strings.Split("graphql-server/tests", string(os.PathSeparator))
// Linux:   ["graphql-server", "tests"]   ← splits correctly
// Windows: ["graphql-server/tests"]      ← single element, no split

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 path package (forward-slash, OS-agnostic) for everything that handles git-supplied paths. Six call sites changed in pkg/ui/panes/filetree/filetree.go:

Before After
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:

Platform Pre-fix Post-fix
Windows (Go 1.26.2 native) TestBuildFullFileTree fails: expected 5 nodes, but got 3 All tests pass
Linux (golang:1.26 Docker container) All tests pass All tests pass — byte-for-byte identical

Linux behavior is unchanged because os.PathSeparator == '/' on Linux already, and path.{Dir,Join} produce identical output to filepath.{Dir,Join} for forward-slash inputs. The fix only affects Windows code paths where the previous behavior was already broken.

TestBuildFullFileTree, TestCollapseTree, TestUncollapsableTree, and TestCloseDirsBelowDepth* all flip from failing to passing on Windows under the fix; no new tests were needed.

Side benefits beyond the file-tree rendering

DirNode.FullPath is also used to:

  • Match against paths in 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.
  • Pass to SetDirPatch in tui.go:1349 — the dir-patch viewer for browsing all changes under a directory. Same fix applies.
  • Get copied to clipboard via 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.

…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 dlvhdr merged commit 19b947d into dlvhdr:main May 2, 2026
3 checks passed
@Booyaka101 Booyaka101 deleted the fix/file-tree-windows-path-separator branch May 4, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File tree structure not shown on Windows (11)

2 participants