fix: prune git worktree tracking after orphaned worktree removal (#428)

When removing an orphaned worktree, `git worktree remove` fails but the
directory is cleaned up via `rm`. Without a subsequent `git worktree prune`,
git's internal tracking remains stale — `git worktree list` continues to
show the entry and the branch stays locked. Add `git worktree prune` after
the rm in both the IPC handler and OrcaRuntimeService to fix this.
This commit is contained in:
Jinjing
2026-04-09 17:46:57 -07:00
committed by GitHub
parent 7a7d287ed2
commit de36c6bafe
3 changed files with 44 additions and 4 deletions
+6 -1
View File
@@ -12,7 +12,7 @@ import type {
import { getPRForBranch } from '../github/client'
import { listWorktrees, addWorktree, removeWorktree } from '../git/worktree'
import { getGitUsername, getDefaultBaseRef, getBranchConflictKind } from '../git/repo'
import { gitExecFileSync } from '../git/runner'
import { gitExecFileAsync, gitExecFileSync } from '../git/runner'
import { isWslPath, parseWslPath, getWslHome } from '../wsl'
import { join } from 'path'
import { listRepoWorktrees } from '../repo-worktrees'
@@ -242,6 +242,11 @@ export function registerWorktreeHandlers(mainWindow: BrowserWindow, store: Store
if (isOrphanedWorktreeError(error)) {
console.warn(`[worktrees] Orphaned worktree detected at ${worktreePath}, cleaning up`)
await rm(worktreePath, { recursive: true, force: true }).catch(() => {})
// Why: `git worktree remove` failed, so git's internal worktree tracking
// (`.git/worktrees/<name>`) is still intact. Without pruning, `git worktree
// list` continues to show the stale entry and the branch it had checked out
// remains locked — other worktrees cannot check it out.
await gitExecFileAsync(['worktree', 'prune'], { cwd: repo.path }).catch(() => {})
store.removeWorktreeMeta(args.worktreeId)
await rebuildAuthorizedRootsCache(store)
notifyWorktreesChanged(mainWindow, repoId)