You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 Remove ipcMain coupling with git worktrees (#457)
## Problem
`ipcMain.ts` directly imported and called git worktree functions
(`removeWorktree`, `pruneWorktrees`), breaking the Runtime abstraction:
- **Leaky abstraction** - `if (type !== 'ssh')` checks in business logic
- **Exposed implementation details** - ipcMain knew about git worktrees
(LocalRuntime internal concept)
- **Inconsistent** - Some workspace operations went through Runtime,
others bypassed it
## Key Insight
**Worktrees are an internal concept of LocalRuntime.** SSHRuntime uses
plain directories. The Runtime interface should never expose
worktree-specific operations.
## Solution
Made `LocalRuntime.deleteWorkspace()` fully idempotent and
self-sufficient, eliminating the need for manual worktree management in
ipcMain.
### 1. LocalRuntime.deleteWorkspace() - Now Idempotent (+31 lines)
- Checks if directory exists before attempting deletion
- Auto-prunes stale git records when directory is already gone
- Handles "not a working tree" errors gracefully by auto-pruning
- Returns success for already-deleted workspaces (idempotent)
### 2. ipcMain.ts - Clean Abstraction (-30 lines)
- Line 608: Fork cleanup now uses `runtime.deleteWorkspace(force=true)`
- Lines 1067-1078: Removed manual `pruneWorktrees()` logic entirely
- Removed `if (metadata.runtimeConfig?.type !== 'ssh')` check
- Removed imports: `removeWorktree`, `pruneWorktrees`
## Benefits
✅ **Proper encapsulation** - Worktree concerns stay in LocalRuntime
✅ **No leaky abstractions** - Zero runtime-specific checks in ipcMain
✅ **Consistent** - All workspace mutations go through Runtime interface
✅ **Idempotent** - deleteWorkspace() succeeds on already-deleted
workspaces
✅ **Zero interface changes** - No new Runtime methods needed
## Testing
```
✅ 796 tests pass
✅ Type checking passes
✅ Net: +8 lines (defensive checks in LocalRuntime)
```
## Context
This PR is part of a series cleaning up git utility organization:
1. Fixed test isolation issues (#PR)
2. Removed 418 lines of dead code (#PR)
3. Consolidated git utilities into single file (#PR)
4. **This PR**: Removed architectural coupling between ipcMain and git
worktrees
_Generated with `cmux`_
0 commit comments