Skip to content

Commit 28f0fb7

Browse files
committed
🤖 Consolidate git utilities by merging gitService into git.ts
Eliminated duplicate WorktreeResult interface and consolidated all git worktree operations into a single file for better organization. Changes: - Moved removeWorktree() and pruneWorktrees() from gitService.ts to git.ts - Removed duplicate WorktreeResult interface (was in both files) - Deleted src/services/gitService.ts (36 lines) - Deleted src/services/gitService.test.ts (10 lines) - Updated ipcMain.ts to import from @/git instead of gitService git.ts now exports all git operations: - listLocalBranches() - getCurrentBranch() - detectDefaultTrunkBranch() - createWorktree() - getMainWorktreeFromWorktree() - removeWorktree() [moved from gitService] - pruneWorktrees() [moved from gitService] All 796 tests pass, type checking passes. _Generated with `cmux`_
1 parent ce6cd26 commit 28f0fb7

File tree

4 files changed

+31
-47
lines changed

4 files changed

+31
-47
lines changed

src/git.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,32 @@ export async function getMainWorktreeFromWorktree(worktreePath: string): Promise
185185
return null;
186186
}
187187
}
188+
189+
export async function removeWorktree(
190+
projectPath: string,
191+
workspacePath: string,
192+
options: { force: boolean } = { force: false }
193+
): Promise<WorktreeResult> {
194+
try {
195+
// Remove the worktree (from the main repository context)
196+
using proc = execAsync(
197+
`git -C "${projectPath}" worktree remove "${workspacePath}" ${options.force ? "--force" : ""}`
198+
);
199+
await proc.result;
200+
return { success: true };
201+
} catch (error) {
202+
const message = error instanceof Error ? error.message : String(error);
203+
return { success: false, error: message };
204+
}
205+
}
206+
207+
export async function pruneWorktrees(projectPath: string): Promise<WorktreeResult> {
208+
try {
209+
using proc = execAsync(`git -C "${projectPath}" worktree prune`);
210+
await proc.result;
211+
return { success: true };
212+
} catch (error) {
213+
const message = error instanceof Error ? error.message : String(error);
214+
return { success: false, error: message };
215+
}
216+
}

src/services/gitService.test.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/services/gitService.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/services/ipcMain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
listLocalBranches,
1111
detectDefaultTrunkBranch,
1212
getCurrentBranch,
13+
removeWorktree,
14+
pruneWorktrees,
1315
} from "@/git";
14-
import { removeWorktree, pruneWorktrees } from "@/services/gitService";
1516
import { AIService } from "@/services/aiService";
1617
import { HistoryService } from "@/services/historyService";
1718
import { PartialService } from "@/services/partialService";

0 commit comments

Comments
 (0)