Skip to content

Commit 933c22a

Browse files
authored
Git - Handle repository paths with a trailing \ character (microsoft#159461)
* Fix another edge case with Windows path that contains a trailing \ character * Pull request feedback
1 parent e4c6aaf commit 933c22a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

extensions/git/src/git.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,6 @@ export class Git {
505505

506506
return path.normalize(pathUri.fsPath);
507507
}
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-
}
515508
}
516509

517510
return repoPath;

extensions/git/src/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ export function pathEquals(a: string, b: string): boolean {
314314
* casing.
315315
*/
316316
export function relativePath(from: string, to: string): string {
317+
// On Windows, there are cases in which `from` is a path that contains a trailing `\` character
318+
// (ex: C:\, \\server\folder\) due to the implementation of `path.normalize()`. This behavior is
319+
// by design as documented in https://github.com/nodejs/node/issues/1765.
320+
if (isWindows) {
321+
from = from.replace(/\\$/, '');
322+
}
323+
317324
if (isDescendant(from, to) && from.length < to.length) {
318325
return to.substring(from.length + 1);
319326
}

0 commit comments

Comments
 (0)