fix(ui): use path.Join for git tree paths on Windows#903
Open
syf2211 wants to merge 1 commit into
Open
Conversation
Git always uses forward slashes for repository paths. Using filepath.Join, filepath.Dir, or filepath.Clean on Windows converts separators to backslashes, which breaks file browser navigation into subdirectories. Replace filepath with path for git logical paths in the UI and git package. Add regression tests for the forward-slash invariant. Fixes charmbracelet#681
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.
Summary
Fix file browser navigation failing on Windows hosts when browsing repository subdirectories. Git always uses forward slashes (
/) for paths;filepath.Join/Dir/Cleanon Windows converts them to backslashes (\), which git does not recognize.Motivation
Fixes #681 — users on Windows (and clients connecting to Windows-hosted servers) could only navigate one directory level deep in the Files tab. Entering a subdirectory either showed no change or duplicated path segments like
\bat.Changes
pkg/ui/pages/repo/files.go— usepath.Join/path.Dirfor browser navigation statepkg/ui/pages/repo/readme.go— usepath.Dirfor readme path displaygit/utils.go— usepath.Join/path.DirinLatestFilepattern matchinggit/repo.go— usepath.Clean(filepath.ToSlash(...))inTreePathgit/tree.go— usepath.JoinforTreeEntrylogical pathsgit/repo_test.go— regression tests for forward-slash invariantOS filesystem paths (data directory, hooks, LFS storage) are unchanged and still correctly use
filepath.Tests
All tests pass, including
testscriptintegration suite (~67s).Notes
Related to closed PR #815 (same root cause; redirected to fork workflow). This version also fixes
TreePathandgit/tree.goentry path construction, which were not covered in #815.