fix(ssh): match the exact worktree created

This commit is contained in:
Neil
2026-08-30 16:36:07 -07:00
committed by GitHub
parent f7d8d7f77a
commit 2ff0ca10d4
2 changed files with 11 additions and 4 deletions
+4 -4
View File
@@ -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/<branchName>` 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')
}
@@ -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',