From 2ff0ca10d4d3c10a5b53f3c31bc19e8f3e8b6bbc Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 30 Aug 2026 16:36:07 -0700 Subject: [PATCH] fix(ssh): match the exact worktree created --- src/main/ipc/worktree-remote.ts | 8 ++++---- src/main/ipc/worktrees-ssh-setup-launch.test.ts | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/ipc/worktree-remote.ts b/src/main/ipc/worktree-remote.ts index edda8ebbbce..5e1f004972b 100644 --- a/src/main/ipc/worktree-remote.ts +++ b/src/main/ipc/worktree-remote.ts @@ -90,7 +90,7 @@ import { shouldSetDisplayName, mergeWorktree } from './worktree-logic' -import { resolveCreatedWorktree } from './created-worktree-reconciliation' +import { findCreatedWorktree, resolveCreatedWorktree } from './created-worktree-reconciliation' import type { BranchPrefixSettings } from '../../shared/branch-prefix' import { getRepoIdFromWorktreeId } from '../../shared/worktree/id' import { parseWorkspaceKey, worktreeWorkspaceKey } from '../../shared/workspace-scope' @@ -1840,9 +1840,9 @@ export async function createRemoteWorktree( const gitWorktrees = await timing.time('list_created_worktree', async () => provider.listWorktrees(repo.path) ) - const created = gitWorktrees.find( - (gw) => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName) - ) + // Match the exact requested path first, then the exact branch ref. Suffix matching can + // select an older `prefix/` worktree when the newly created row is present. + const created = findCreatedWorktree(gitWorktrees, remotePath, branchName) if (!created) { throw new Error('Worktree created but not found in listing') } diff --git a/src/main/ipc/worktrees-ssh-setup-launch.test.ts b/src/main/ipc/worktrees-ssh-setup-launch.test.ts index f3a76bdacde..a0735bfd50d 100644 --- a/src/main/ipc/worktrees-ssh-setup-launch.test.ts +++ b/src/main/ipc/worktrees-ssh-setup-launch.test.ts @@ -126,6 +126,13 @@ describe('registerWorktreeHandlers', () => { fetchRemoteTrackingRef: vi.fn().mockResolvedValue(undefined), addWorktree: vi.fn().mockResolvedValue(undefined), listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/remote/old-improve-dashboard', + head: 'old123', + branch: 'refs/heads/archive/improve-dashboard', + isBare: false, + isMainWorktree: false + }, { path: '/remote/repo-improve-dashboard', head: 'abc123',