Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(worktree): fold path case only for drive-letter/UNC paths, not any backslash

reviewf2e45897ddc3
diff --git a/src/shared/worktree.test.ts b/src/shared/worktree.test.ts
index 707f7e37c..2701a5c69 100644
--- a/src/shared/worktree.test.ts
+++ b/src/shared/worktree.test.ts
@@ -186,6 +186,11 @@ describe('worktreeFromCreate', () => {
worktreeFromCreate({ repoPath: 'C:\\r', mode: 'new', branch: 'b', baseRef: 'main', path: 'C:\\r.worktrees\\B' }).path
).toBe('C:/r.worktrees/B')
})
+ it('leaves a POSIX path with a backslash in a name untouched', () => {
+ expect(
+ worktreeFromCreate({ repoPath: '/r', mode: 'new', branch: 'b', baseRef: 'main', path: '/r.worktrees/a\\b' }).path
+ ).toBe('/r.worktrees/a\\b')
+ })
it('trims the collected fields', () => {
const wt = worktreeFromCreate({
repoPath: ' /repo ',
@@ -283,6 +288,11 @@ describe('worktreePathKey (Windows-shaped paths compare by identity, POSIX by ex
expect(worktreePathKey('/A/wt')).not.toBe(worktreePathKey('/a/wt'))
expect(worktreePathKey(' /x ')).toBe('/x')
})
+ it('does not fold a POSIX path that merely contains a backslash (a legal filename char there)', () => {
+ expect(worktreePathKey('/home/u/A\\b/')).toBe('/home/u/A\\b')
+ expect(worktreePathKey('/home/u/A\\b')).not.toBe(worktreePathKey('/home/u/a/b'))
+ expect(isAncestorPath('/home/u/a', '/home/u/A\\b')).toBe(false)
+ })
it('isAncestorPath matches across separators and case on Windows paths only', () => {
expect(isAncestorPath('C:/Users', 'C:\\Users\\x')).toBe(true)
expect(isAncestorPath('c:\\users\\', 'C:/Users/x/y')).toBe(true)
diff --git a/src/shared/worktree.ts b/src/shared/worktree.ts
index b8054fe3b..c526880e4 100644
--- a/src/shared/worktree.ts
+++ b/src/shared/worktree.ts
@@ -333,9 +333,10 @@ export function worktreeFromCreate(v: WorktreeCreateValue): GroupWorktree {
repoPath: v.repoPath.trim(),
branch: v.branch.trim(),
baseRef: v.baseRef.trim() || DEFAULT_BASE_REF,
- // '/'-separated (case kept), the shape `git worktree list` prints on every platform, so the
- // binding and git agree without a key fold. A POSIX path has no backslash: unchanged.
- path: v.path.trim().replace(/\\/g, '/'),
+ // A Windows path is stored '/'-separated (case kept), the shape `git worktree list` prints, so
+ // the binding and git agree without a key fold. A POSIX path is untouched — a backslash is a
+ // legal filename character there, not a separator.
+ path: isWindowsShapedPath(v.path.trim()) ? v.path.trim().replace(/\\/g, '/') : v.path.trim(),
createdByApp: true
}
}
@@ -401,9 +402,9 @@ export function parseWorktreePorcelain(out: string): WorktreeEntry[] {
/**
* The identity key of a worktree/repo path, for COMPARING paths — never for using one. Git prints
* `C:/r/wt` on Windows while a typed or pasted binding says `C:\r\wt` (or `c:/…`), and NTFS is
- * case-insensitive by default, so a Windows-shaped path (any backslash, a drive letter, or UNC
- * `//`) is folded to forward slashes and lower case. A POSIX path keeps its exact case and is only
- * stripped of trailing slashes — byte-identical to the comparison this replaced. Keyed on the
+ * case-insensitive by default, so a Windows-shaped path (a drive letter or UNC — see
+ * `isWindowsShapedPath`) is folded to forward slashes and lower case. A POSIX path keeps its exact
+ * case and is only stripped of trailing slashes — byte-identical to the comparison this replaced. Keyed on the
* path's SHAPE, not on `process.platform`: this module runs in the renderer, whose platform is not
* the core's.
*/
@@ -411,9 +412,16 @@ export function worktreePathKey(p: string): string {
return pathKey(p.trim())
}
+/** An absolute Windows path: a drive letter (`C:`) or UNC (`\\server`, or `//server` as git prints
+ * it). Shape, not a stray backslash: on POSIX `\\` is a legal filename character, and folding such
+ * a path's case would make two distinct POSIX directories compare equal. */
+export function isWindowsShapedPath(t: string): boolean {
+ return /^[A-Za-z]:|^[\\/]{2}/.test(t)
+}
+
/** `worktreePathKey` without the trim — `isAncestorPath` and the removal guard never trimmed. */
function pathKey(t: string): string {
- if (!/\\|^[A-Za-z]:|^\/\//.test(t)) return t.replace(/\/+$/, '')
+ if (!isWindowsShapedPath(t)) return t.replace(/\/+$/, '')
return t.replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase()
}