Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Windows paths in git: URI construction #6

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

ChrisJohnsen
Copy link
Contributor

This fixes #2 for me and seems like it should be platform independent.

Tested via "Launch Extension" and by npx @vscode/vsce package and loading the resulting .vsix file.
Tested using VS Code 1.91.1, Git 2.45.2.windows.1, Windows 10 22H2 build 19045.4651.

Alternative formulations that don't use gitApi.toGitUri are possible:

    vscode.Uri.from({ …, path: "/" + path, … })

    vscode.Uri.from({ …, path: vscode.Uri.file(path).path, … })

    vscode.Uri.file(path).with({ scheme: …, query: … })

The first alternative works, but mixes forward- and back-slashes (the
incoming path has backslashes).

The last two alternatives should be equivalent and give the same result
as the version in this commit. All of them convert the directory
separators to forward slashes, so the final URI looks like (e.g.)

    git:///c%3A/Users/me/Documents/…?…

Note: The path property in the encoded query component seems like it
must use backslashes on Windows. toGitUri uses fsPath for the encoded
path property. Also, I got a different failure opening the vscode.diff
link when I tried using slashes in the query's path property.

toGitUrl: https://github.com/microsoft/vscode/blob/65a6a2f783dbc87fb3b1408c6a9b3e8d455a60a2/extensions/git/src/uri.ts#L32
@mk12
Copy link
Owner

mk12 commented Jul 18, 2024

Amazing, thanks! I never noticed there was a toGitUri method.

@mk12 mk12 merged commit e8d12c9 into mk12:main Jul 18, 2024
mk12 added a commit that referenced this pull request Jul 18, 2024
@mk12
Copy link
Owner

mk12 commented Jul 18, 2024

Just published 0.2.8 with this fix.

@ChrisJohnsen ChrisJohnsen deleted the windows-git-uri branch January 16, 2025 09:34
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.

Blame not working on Windows due to different path separator
2 participants