fix: recover missing worktree deletes (#4811)

This commit is contained in:
Jinjing
2026-06-07 11:01:26 -07:00
committed by GitHub
parent f9e8616bb6
commit bb40dcd028
8 changed files with 94 additions and 9 deletions
@@ -25,6 +25,20 @@ describe('getDeleteWorktreeToastCopy', () => {
})
})
it('uses stale-row guidance when Git already removed the worktree directory', () => {
expect(
getDeleteWorktreeToastCopy(
'feature/foo',
true,
'Worktree is no longer registered with Git and its directory is already gone.'
)
).toEqual({
title: 'Failed to delete workspace feature/foo',
description: 'Git already removed this workspace. Use Force Delete to clear it from Orca.',
isDestructive: false
})
})
it('preserves the raw error when force delete is unavailable', () => {
expect(getDeleteWorktreeToastCopy('feature/foo', false, 'permission denied')).toEqual({
title: 'Failed to delete workspace feature/foo',
@@ -18,6 +18,15 @@ export function getDeleteWorktreeToastCopy(
isDestructive: false
}
}
if (
error.includes('Worktree is no longer registered with Git and its directory is already gone.')
) {
return {
title: `Failed to delete workspace ${worktreeName}`,
description: 'Git already removed this workspace. Use Force Delete to clear it from Orca.',
isDestructive: false
}
}
return {
title: `Failed to delete workspace ${worktreeName}`,
description: 'It has changed files. Use Force Delete to delete it anyway.',
@@ -320,6 +320,33 @@ describe('removeWorktree cascade', () => {
})
})
it('offers force delete when Git already removed an unregistered worktree', async () => {
const store = createTestStore()
const worktreeId = 'repo1::/workspace/deleted-wt'
const error =
"Error invoking remote method 'worktrees:remove': Error: Worktree is no longer registered with Git and its directory is already gone."
mockApi.worktrees.remove.mockRejectedValueOnce(new Error(error))
seedStore(store, {
worktreesByRepo: {
repo1: [makeWorktree({ id: worktreeId, repoId: 'repo1' })]
},
tabsByWorktree: {},
ptyIdsByTabId: {},
terminalLayoutsByTabId: {}
})
const result = await store.getState().removeWorktree(worktreeId)
expect(result).toEqual({ ok: false, error })
expect(store.getState().deleteStateByWorktreeId[worktreeId]).toEqual({
isDeleting: false,
error,
canForceDelete: true
})
})
it('sets canForceDelete=false when force=true removal fails', async () => {
const store = createTestStore()
const worktreeId = 'repo1::/path/wt1'
+2 -1
View File
@@ -237,7 +237,8 @@ function toVisibleTabType(contentType: string): WorkspaceVisibleTabType {
const FORCE_RETRYABLE_WORKTREE_REMOVAL_MESSAGES = [
'Worktree has uncommitted or untracked changes',
'contains modified or untracked files',
'Worktree is no longer registered with Git but its directory remains'
'Worktree is no longer registered with Git but its directory remains',
'Worktree is no longer registered with Git and its directory is already gone'
] as const
// Why: local preflight formatting can surface raw git porcelain instead of the