| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | import { spawn } from "node:child_process"; | 1 | import { spawn } from "node:child_process"; |
| | 2 | import fs from "node:fs"; |
| 2 | import os from "node:os"; | 3 | import os from "node:os"; |
| 3 | import path from "node:path"; | 4 | import path from "node:path"; |
| 4 | | 5 | |
| ... | @@ -131,12 +132,14 @@ export async function listGitBranches(input: GitListBranchesInput): Promise<GitL | ... | @@ -131,12 +132,14 @@ export async function listGitBranches(input: GitListBranchesInput): Promise<GitL |
| 131 | defaultRef.code === 0 ? defaultRef.stdout.trim().replace(/^refs\/remotes\/origin\//, "") : null; | 132 | defaultRef.code === 0 ? defaultRef.stdout.trim().replace(/^refs\/remotes\/origin\//, "") : null; |
| 132 | | 133 | |
| 133 | // Build branch-name → worktree-path map from porcelain output. | 134 | // Build branch-name → worktree-path map from porcelain output. |
| | 135 | // Only include worktrees whose directories still exist on disk (skip prunable/stale ones). |
| 134 | const worktreeMap = new Map<string, string>(); | 136 | const worktreeMap = new Map<string, string>(); |
| 135 | if (worktreeList.code === 0) { | 137 | if (worktreeList.code === 0) { |
| 136 | let currentPath: string | null = null; | 138 | let currentPath: string | null = null; |
| 137 | for (const line of worktreeList.stdout.split("\n")) { | 139 | for (const line of worktreeList.stdout.split("\n")) { |
| 138 | if (line.startsWith("worktree ")) { | 140 | if (line.startsWith("worktree ")) { |
| 139 | currentPath = line.slice("worktree ".length); | 141 | currentPath = line.slice("worktree ".length); |
| | 142 | if (!fs.existsSync(currentPath)) currentPath = null; |
| 140 | } else if (line.startsWith("branch refs/heads/") && currentPath) { | 143 | } else if (line.startsWith("branch refs/heads/") && currentPath) { |
| 141 | worktreeMap.set(line.slice("branch refs/heads/".length), currentPath); | 144 | worktreeMap.set(line.slice("branch refs/heads/".length), currentPath); |
| 142 | } else if (line === "") { | 145 | } else if (line === "") { |