diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 18d66247661e1..0ccf22301c419 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -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) { @@ -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;