From 57b9704c83cfa43cb324e1fbe2f4db3108507375 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Sat, 30 May 2026 07:42:51 -0700 Subject: [PATCH] Fix Windows drive-root path matching Co-authored-by: Orca --- .../components/right-sidebar/file-explorer-paths.test.ts | 7 +++++++ src/renderer/src/lib/path.test.ts | 4 ++++ src/renderer/src/lib/path.ts | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/file-explorer-paths.test.ts b/src/renderer/src/components/right-sidebar/file-explorer-paths.test.ts index ae4bc4e7b..bbc373d6a 100644 --- a/src/renderer/src/components/right-sidebar/file-explorer-paths.test.ts +++ b/src/renderer/src/components/right-sidebar/file-explorer-paths.test.ts @@ -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' + ]) + }) }) diff --git a/src/renderer/src/lib/path.test.ts b/src/renderer/src/lib/path.test.ts index 71742c303..c40ce80d7 100644 --- a/src/renderer/src/lib/path.test.ts +++ b/src/renderer/src/lib/path.test.ts @@ -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') diff --git a/src/renderer/src/lib/path.ts b/src/renderer/src/lib/path.ts index c96bef7e8..8437f4032 100644 --- a/src/renderer/src/lib/path.ts +++ b/src/renderer/src/lib/path.ts @@ -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)) }