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',