mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Git - fix relativePath() edge case (#194653)
This commit is contained in:
parent
8aced5c030
commit
d4fb31c56d
|
@ -311,18 +311,19 @@ export function pathEquals(a: string, b: string): boolean {
|
|||
* Given the `repository.root` compute the relative path while trying to preserve
|
||||
* the casing of the resource URI. The `repository.root` segment of the path can
|
||||
* have a casing mismatch if the folder/workspace is being opened with incorrect
|
||||
* casing.
|
||||
* casing which is why we attempt to use substring() before relative().
|
||||
*/
|
||||
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(/\\$/, '');
|
||||
// There are cases in which the `from` path may contain a trailing separator at
|
||||
// the end (ex: "C:\", "\\server\folder\" (Windows) or "/" (Linux/macOS)) which
|
||||
// is by design as documented in https://github.com/nodejs/node/issues/1765. If
|
||||
// the trailing separator is missing, we add it.
|
||||
if (from.charAt(from.length - 1) !== sep) {
|
||||
from += sep;
|
||||
}
|
||||
|
||||
if (isDescendant(from, to) && from.length < to.length) {
|
||||
return to.substring(from.length + 1);
|
||||
return to.substring(from.length);
|
||||
}
|
||||
|
||||
// Fallback to `path.relative`
|
||||
|
|
Loading…
Reference in a new issue