Delete orphaned worktree when removing a thread #23
Mergedjuliusmarmingemerged 6 commits into
main fromcodething/b0e2dc22merged by juliusmarminge View on GitHub- @@ -284,3 +297,16 @@284297 }285298286299 dispatch({ type: "DELETE_THREAD", threadId });300+301+ if (!shouldDeleteWorktree || !orphanedWorktreePath) {302+ return;303+ }304+305+ try {306+ await api.git.removeWorktree({307+ cwd: threadProject?.cwd ?? orphanedWorktreePath,308+ path: orphanedWorktreePath,309+ });310+ } catch {311+ // Worktree deletion is best-effort and should not block thread deletion.312+ }
- @@ -284,3 +297,11 @@284297 }285298286299 dispatch({ type: "DELETE_THREAD", threadId });300+301+ if (!shouldDeleteWorktree || !orphanedWorktreePath) {302+ return;303+ }304+305+ try {306+ await api.git.removeWorktree({307+ cwd: threadProject?.cwd ?? orphanedWorktreePath,@@ -284,3 +297,16 @@284297 }285298286299 dispatch({ type: "DELETE_THREAD", threadId });300+301+ if (!shouldDeleteWorktree || !orphanedWorktreePath) {302+ return;303+ }304+305+ try {306+ await api.git.removeWorktree({307+ cwd: threadProject?.cwd ?? orphanedWorktreePath,308+ path: orphanedWorktreePath,309+ });310+ } catch {311+ // Worktree deletion is best-effort and should not block thread deletion.312+ }
- @@ -142,3 +144,12 @@142144 return result.filePaths[0] ?? null;143145 });144146147+ ipcMain.removeHandler(CONFIRM_CHANNEL);148+ ipcMain.handle(CONFIRM_CHANNEL, async (_event, message: unknown) => {149+ if (typeof message !== "string") {150+ return false;151+ }152+153+ const owner = BrowserWindow.getFocusedWindow() ?? mainWindow;154+ return showDesktopConfirmDialog(message, owner);155+ });@@ -60,3 +60,9 @@6060 if (!window.desktopBridge) return null;6161 return window.desktopBridge.pickFolder();6262 },63+ confirm: async (message) => {64+ if (window.desktopBridge) {65+ return window.desktopBridge.confirm(message);66+ }67+ return window.confirm(message);68+ },
- apps/web/src/components/Sidebar.tsx lines 272 to 281Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -262,3 +263,15 @@262263263264 const thread = state.threads.find((t) => t.id === threadId);264265 if (!thread) return;266+ const threadProject = state.projects.find((project) => project.id === thread.projectId);267+ const orphanedWorktreePath = getOrphanedWorktreePathForThread(state.threads, threadId);268+ const shouldDeleteWorktree =269+ orphanedWorktreePath !== null &&270+ (await api.dialogs.confirm(271+ [272+ "This thread is the only one linked to this worktree:",273+ orphanedWorktreePath,274+ "",275+ "Delete the worktree too?",276+ ].join("\n"),277+ ));
juliusmarminge merged this293f7b1
juliusmarminge closed this
Sign in to join this conversation.
Walkthrough#
Adds utilities to detect orphaned Git worktree paths and format them, integrates a desktop confirmation dialog (IPC, preload bridge, main handler), updates renderer native API, uses confirmation and best-effort worktree removal when deleting threads, and adds tests for utilities and the dialog.
Changes#
apps/web/src/worktreeCleanup.ts,apps/web/src/worktreeCleanup.test.tsgetOrphanedWorktreePathForThreadandformatWorktreePathForDisplaywith internal normalization; tests cover missing thread/worktree, uniqueness, shared paths, path formatting (unix/windows/outside paths, trailing slashes).apps/web/src/components/Sidebar.tsxthreadProject,orphanedWorktreePath,displayWorktreePath, derivescanDeleteWorktree/shouldDeleteWorktreewith user confirmation, callsgit.removeWorktreebest-effort (errors ignored). Extends dependency arrays to includestate.projects.apps/desktop/src/confirmDialog.ts,apps/desktop/src/confirmDialog.test.tsshowDesktopConfirmDialog(message, ownerWindow)that trims/validates message and shows a No/Yes dialog; tests mockdialog.showMessageBoxfor empty message, focused window, and no-window scenarios.apps/desktop/src/main.ts,apps/desktop/src/preload.tsdesktop:confirmin main, delegating toshowDesktopConfirmDialog; exposesdesktopBridge.confirm(message): Promise<boolean>via preload.apps/web/src/wsNativeApi.ts,apps/web/src/vite-env.d.ts,packages/contracts/src/ipc.tsdialogs.confirm(message): Promise<boolean>to contracts andDesktopBridgetyping;wsNativeApidelegates towindow.desktopBridge.confirmwhen available, else falls back towindow.confirm.package.jsonSequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
⚔️
apps/desktop/src/main.ts(content)⚔️
apps/desktop/src/preload.ts(content)⚔️
apps/web/src/components/ChatView.tsx(content)⚔️
apps/web/src/components/Sidebar.tsx(content)⚔️
apps/web/src/vite-env.d.ts(content)⚔️
apps/web/src/wsNativeApi.ts(content)⚔️
packages/contracts/src/ipc.ts(content)These conflicts must be resolved before merging into
main.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉
Comment `@coderabbitai help` to get the list of available commands and usage tips.