Skip to content

Fix Copy Path separator for git: URIs on Remote SSH#309252

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-copy-path-separator-ssh-303207
Open

Fix Copy Path separator for git: URIs on Remote SSH#309252
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-copy-path-separator-ssh-303207

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Summary

  • Fix tildify() returning un-normalized (backslash) paths when tildification fails on a Windows client targeting a non-Windows remote OS
  • This caused the Copy Path command on staged files (git: URI scheme) to return \path\to\file instead of /path/to/file when using Remote SSH from Windows to Linux
  • Add test coverage for the cross-scheme tildification non-match scenario

Problem

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 to getPathLabel(). This function calls tildify() to shorten home-directory paths with ~. The tildify() 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 raw path from tildify() when tildification does not match. This is safe because:

  • tildify() is only reached when os !== Windows (it returns early for Windows targets)
  • When isWindows is false, normalizedPath === path (no behavioral change)
  • When isWindows is true, normalizedPath has the correct forward slashes for the non-Windows target OS

Fixes #303207

Test plan

  • Added test case for getPathLabel() with a git: scheme URI, vscode-remote: user home, and Linux/macOS target OS where the path is not under the user home
  • Verify existing labels.test.ts tests pass
  • Manual test: Windows client, Remote SSH to Linux, stage a file, open staged diff, Copy Path should produce forward-slash path

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
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.

Copy Path feature returns string with Path Seperator for windows on Linux SSH only for staged files.

2 participants