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

Git - fix edge case with Windows mapped drives #154342

Merged
merged 2 commits into from Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions extensions/git/src/git.ts
Expand Up @@ -475,8 +475,9 @@ export class Git {
const repoPath = path.normalize(result.stdout.trimLeft().replace(/[\r\n]+$/, ''));

if (isWindows) {
// On Git 2.25+ if you call `rev-parse --show-toplevel` on a mapped drive, instead of getting the mapped drive path back, you get the UNC path for the mapped drive.
// So we will try to normalize it back to the mapped drive path, if possible
// On Git 2.25+ if you call `rev-parse --show-toplevel` on a mapped drive, instead of getting the mapped
// drive path back, you get the UNC path for the mapped drive. So we will try to normalize it back to the
// mapped drive path, if possible
const repoUri = Uri.file(repoPath);
const pathUri = Uri.file(repositoryPath);
if (repoUri.authority.length !== 0 && pathUri.authority.length === 0) {
Expand Down Expand Up @@ -504,6 +505,13 @@ export class Git {

return path.normalize(pathUri.fsPath);
}

// On Windows, there are cases in which the normalized path for a mapped folder contains a trailing `\`
// character (ex: \\server\folder\) due to the implementation of `path.normalize()`. This behaviour is
// by design as documented in https://github.com/nodejs/node/issues/1765.
if (repoUri.authority.length !== 0) {
return repoPath.replace(/\\$/, '');
}
}

return repoPath;
Expand Down