Fix Copy Path separator for git: URIs on Remote SSH#309252
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix Copy Path separator for git: URIs on Remote SSH#309252yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When using Remote SSH from a Windows client to a Linux host, the Copy Path command on staged files (which use the git: URI scheme) returned backslash-separated paths instead of forward slashes. The root cause was in the tildify() function: when the path does not fall under the user home directory and the local OS is Windows, the function normalized the path to forward slashes for comparison but returned the original un-normalized path (with backslashes) in the non-match fallback. Since git: URIs have no label formatter (unlike vscode-remote: URIs), they go through getPathLabel() which calls tildify(), and the backslashes leaked into the final label. Return the normalized path instead so that the POSIX separators are preserved when the target OS is not Windows. Fixes microsoft#303207
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
tildify()returning un-normalized (backslash) paths when tildification fails on a Windows client targeting a non-Windows remote OS\path\to\fileinstead of/path/to/filewhen using Remote SSH from Windows to LinuxProblem
When using Remote SSH from a Windows client to a Linux host, the Copy Path (Shift+Alt+C) command on staged files returned backslash-separated Windows paths. Unstaged files were unaffected because their URIs use the
vscode-remote:scheme which has a dedicated label formatter.Staged files use the
git:URI scheme, which has no label formatter and falls through togetPathLabel(). This function callstildify()to shorten home-directory paths with~. Thetildify()function normalizes the path to forward slashes internally for comparison, but when the path is not under the user home directory, it returned the original un-normalized path (with Windows backslashes) instead of the normalized one.Fix
Return the
normalizedPath(with POSIX separators) instead of the rawpathfromtildify()when tildification does not match. This is safe because:tildify()is only reached whenos !== Windows(it returns early for Windows targets)isWindowsisfalse,normalizedPath === path(no behavioral change)isWindowsistrue,normalizedPathhas the correct forward slashes for the non-Windows target OSFixes #303207
Test plan
getPathLabel()with agit:scheme URI,vscode-remote:user home, and Linux/macOS target OS where the path is not under the user homelabels.test.tstests pass