Git - improvements to relative path calculation (#245001)

Git - relative path using both the repository root and repository real root
This commit is contained in:
Ladislau Szomoru
2025-03-28 20:15:52 +01:00
committed by GitHub
parent 2e378e5137
commit 82839a3b65
2 changed files with 62 additions and 23 deletions

View File

@@ -328,6 +328,10 @@ export function pathEquals(a: string, b: string): boolean {
* casing which is why we attempt to use substring() before relative().
*/
export function relativePath(from: string, to: string): string {
return relativePathWithNoFallback(from, to) ?? relative(from, to);
}
export function relativePathWithNoFallback(from: string, to: string): string | undefined {
// 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
@@ -340,8 +344,7 @@ export function relativePath(from: string, to: string): string {
return to.substring(from.length);
}
// Fallback to `path.relative`
return relative(from, to);
return undefined;
}
export function* splitInChunks(array: string[], maxChunkLength: number): IterableIterator<string[]> {