Skip to content

Commit acd1db2

Browse files
authored
Git - fix edge case with Windows mapped drives (microsoft#154342)
* Fix an edge case with computing relative path on Windows * Refactor the fix
1 parent d4bb7e3 commit acd1db2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

extensions/git/src/git.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ export class Git {
475475
const repoPath = path.normalize(result.stdout.trimLeft().replace(/[\r\n]+$/, ''));
476476

477477
if (isWindows) {
478-
// 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.
479-
// So we will try to normalize it back to the mapped drive path, if possible
478+
// On Git 2.25+ if you call `rev-parse --show-toplevel` on a mapped drive, instead of getting the mapped
479+
// drive path back, you get the UNC path for the mapped drive. So we will try to normalize it back to the
480+
// mapped drive path, if possible
480481
const repoUri = Uri.file(repoPath);
481482
const pathUri = Uri.file(repositoryPath);
482483
if (repoUri.authority.length !== 0 && pathUri.authority.length === 0) {
@@ -504,6 +505,13 @@ export class Git {
504505

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

509517
return repoPath;

0 commit comments

Comments
 (0)