Git - Handle repository paths with a trailing \ character (#159461)

* Fix another edge case with Windows path that contains a trailing \ character

* Pull request feedback
This commit is contained in:
Ladislau Szomoru
2022-08-30 11:58:45 +02:00
committed by GitHub
parent e4c6aaf84a
commit 933c22a53f
2 changed files with 7 additions and 7 deletions

View File

@@ -505,13 +505,6 @@ 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;

View File

@@ -314,6 +314,13 @@ export function pathEquals(a: string, b: string): boolean {
* casing.
*/
export function relativePath(from: string, to: string): string {
// On Windows, there are cases in which `from` is a path that contains a trailing `\` character
// (ex: C:\, \\server\folder\) due to the implementation of `path.normalize()`. This behavior is
// by design as documented in https://github.com/nodejs/node/issues/1765.
if (isWindows) {
from = from.replace(/\\$/, '');
}
if (isDescendant(from, to) && from.length < to.length) {
return to.substring(from.length + 1);
}