From 94420192359d68c03241f03f47cf8d670abafa15 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Feb 2026 15:48:41 -0800 Subject: [PATCH] Filter out stale worktree paths from branch listing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Worktrees in /tmp or other ephemeral locations get cleaned by the OS but remain in git's worktree list as "prunable". These stale entries caused branches to show a worktree label pointing at a non-existent directory, leading to broken state when selected. Now validates each worktree path with existsSync before including it in the branch→worktreePath map. Co-Authored-By: Claude Opus 4.6 --- apps/server/src/git.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/server/src/git.ts b/apps/server/src/git.ts index 718cf7e47e..34b3b0a0fa 100644 --- a/apps/server/src/git.ts +++ b/apps/server/src/git.ts @@ -1,4 +1,5 @@ import { spawn } from "node:child_process"; +import fs from "node:fs"; import os from "node:os"; import path from "node:path"; @@ -131,12 +132,14 @@ export async function listGitBranches(input: GitListBranchesInput): Promise(); if (worktreeList.code === 0) { let currentPath: string | null = null; for (const line of worktreeList.stdout.split("\n")) { if (line.startsWith("worktree ")) { currentPath = line.slice("worktree ".length); + if (!fs.existsSync(currentPath)) currentPath = null; } else if (line.startsWith("branch refs/heads/") && currentPath) { worktreeMap.set(line.slice("branch refs/heads/".length), currentPath); } else if (line === "") {