* List all worktrees (supports subdirectories)
(params: ListWorkTreesParams)
| 1314 | * List all worktrees (supports subdirectories) |
| 1315 | */ |
| 1316 | async function handleListWorkTrees(params: ListWorkTreesParams): Promise<ListWorkTreesResponse> { |
| 1317 | const startTime = Date.now() |
| 1318 | logger.info("[Git:listWorkTrees] Listing worktrees", JSON.stringify({ repoDir: params.repoDir })) |
| 1319 | |
| 1320 | try { |
| 1321 | validateRepoDir(params.repoDir) |
| 1322 | |
| 1323 | // Resolve git info (handles subdirectories) |
| 1324 | const { repoRoot } = await resolveGitInfo(params.repoDir) |
| 1325 | |
| 1326 | const listResult = await execGit(["worktree", "list", "--porcelain"], repoRoot) |
| 1327 | if (!listResult.success) { |
| 1328 | throw new Error(`Failed to list worktrees: ${listResult.stderr}`) |
| 1329 | } |
| 1330 | |
| 1331 | const allWorktrees = parseWorktreeList(listResult.stdout) |
| 1332 | const baseDir = getWorktreeBaseDir() |
| 1333 | |
| 1334 | // Filter for only our managed worktrees |
| 1335 | const worktrees = allWorktrees.filter((wt) => wt.path.startsWith(baseDir)) |
| 1336 | |
| 1337 | logger.info("[Git:listWorkTrees] Worktrees listed", JSON.stringify({ count: worktrees.length, duration: Date.now() - startTime })) |
| 1338 | return { worktrees } |
| 1339 | } catch (error: any) { |
| 1340 | logger.error("[Git:listWorkTrees] Error:", JSON.stringify({ error: error.message, stack: error.stack, duration: Date.now() - startTime })) |
| 1341 | throw error |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * Commit changes in a worktree |
no test coverage detected