Fix Windows drive-root path matching

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo-H
2026-05-31 02:32:23 -07:00
committed by Neil
co-authored by Orca
parent a83afd5a11
commit 57b9704c83
3 changed files with 18 additions and 2 deletions
@@ -35,4 +35,11 @@ describe('file explorer path helpers', () => {
])
expect(getRevealAncestorDirs('/repo', '/Repo/Src/File.ts')).toBeNull()
})
it('builds reveal ancestors for Windows drive-root worktrees', () => {
expect(getRevealAncestorDirs('C:\\', 'c:\\repo\\src\\app.ts')).toEqual([
'C:\\repo',
'C:\\repo\\src'
])
})
})
+4
View File
@@ -26,6 +26,10 @@ describe('getRelativePathInsideRoot', () => {
expect(getRelativePathInsideRoot('C:\\Repo\\Docs\\Plan.md', 'c:\\repo')).toBe('Docs/Plan.md')
})
it('matches Windows drive-root paths without adding an extra separator', () => {
expect(getRelativePathInsideRoot('C:\\Repo\\Docs\\Plan.md', 'c:\\')).toBe('Repo/Docs/Plan.md')
})
it('matches Windows UNC paths case-insensitively', () => {
expect(
getRelativePathInsideRoot('\\\\Server\\Share\\Repo\\Docs\\Plan.md', '\\\\server\\share\\repo')
+7 -2
View File
@@ -24,6 +24,9 @@ function stripTrailingAbsoluteSeparators(path: string): string {
if (path === '/') {
return path
}
if (/^[A-Za-z]:\/$/.test(path)) {
return path
}
return path.replace(/\/+$/, '')
}
@@ -52,12 +55,14 @@ export function getRelativePathInsideRoot(
return ''
}
const rootPrefix = normalizedRoot === '/' ? '/' : `${comparisonRoot}/`
// Why: POSIX and Windows drive roots already include their trailing separator.
const isRootPath = normalizedRoot === '/' || /^[A-Za-z]:\/$/.test(normalizedRoot)
const rootPrefix = isRootPath ? comparisonRoot : `${comparisonRoot}/`
if (!comparisonFilePath.startsWith(rootPrefix)) {
return null
}
const sliceStart = normalizedRoot === '/' ? 1 : normalizedRoot.length + 1
const sliceStart = isRootPath ? normalizedRoot.length : normalizedRoot.length + 1
return normalizeRelativePath(normalizedFilePath.slice(sliceStart))
}