Skip to content

Commit 75b9ea0

Browse files
authored
refactor: remove worktree service (#278)
1 parent 30ecde6 commit 75b9ea0

8 files changed

Lines changed: 34 additions & 134 deletions

File tree

apps/array/src/main/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
import { registerShellIpc } from "./services/shell.js";
4747
import { registerAutoUpdater } from "./services/updates.js";
4848
import { registerWorkspaceIpc } from "./services/workspace/index.js";
49-
import { registerWorktreeIpc } from "./services/worktree.js";
5049

5150
const __filename = fileURLToPath(import.meta.url);
5251
const __dirname = path.dirname(__filename);
@@ -298,6 +297,5 @@ registerOAuthHandlers();
298297
registerGitIpc();
299298
registerAgentIpc(taskControllers, () => mainWindow);
300299
registerFoldersIpc(() => mainWindow);
301-
registerWorktreeIpc();
302300
registerShellIpc();
303301
registerWorkspaceIpc(() => mainWindow);

apps/array/src/main/preload.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
Workspace,
99
WorkspaceInfo,
1010
WorkspaceTerminalInfo,
11-
WorktreeInfo,
1211
} from "../shared/types";
1312
import type { CloudRegion, OAuthTokenResponse } from "../shared/types/oauth";
1413
import "electron-log/preload";
@@ -237,29 +236,6 @@ contextBridge.exposeInMainWorld("electronAPI", {
237236
errors: Array<{ path: string; error: string }>;
238237
}> => ipcRenderer.invoke("cleanup-orphaned-worktrees", mainRepoPath),
239238
},
240-
// Worktree API
241-
worktree: {
242-
create: (mainRepoPath: string): Promise<WorktreeInfo> =>
243-
ipcRenderer.invoke("worktree-create", mainRepoPath),
244-
delete: (mainRepoPath: string, worktreePath: string): Promise<void> =>
245-
ipcRenderer.invoke("worktree-delete", mainRepoPath, worktreePath),
246-
getInfo: (
247-
mainRepoPath: string,
248-
worktreePath: string,
249-
): Promise<WorktreeInfo | null> =>
250-
ipcRenderer.invoke("worktree-get-info", mainRepoPath, worktreePath),
251-
exists: (mainRepoPath: string, name: string): Promise<boolean> =>
252-
ipcRenderer.invoke("worktree-exists", mainRepoPath, name),
253-
list: (mainRepoPath: string): Promise<WorktreeInfo[]> =>
254-
ipcRenderer.invoke("worktree-list", mainRepoPath),
255-
isWorktree: (mainRepoPath: string, repoPath: string): Promise<boolean> =>
256-
ipcRenderer.invoke("worktree-is-worktree", mainRepoPath, repoPath),
257-
getMainRepoPath: (
258-
mainRepoPath: string,
259-
worktreePath: string,
260-
): Promise<string | null> =>
261-
ipcRenderer.invoke("worktree-get-main-repo", mainRepoPath, worktreePath),
262-
},
263239
// Workspace API
264240
workspace: {
265241
create: (options: CreateWorkspaceOptions): Promise<WorkspaceInfo> =>

apps/array/src/main/services/folders.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { logger } from "../lib/logger";
1010
import { clearAllStoreData, foldersStore } from "../utils/store";
1111
import { isGitRepository } from "./git";
1212
import { getWorktreeLocation } from "./settingsStore";
13-
import { deleteWorktreeIfExists } from "./worktreeUtils";
1413

1514
const execAsync = promisify(exec);
1615

@@ -63,10 +62,19 @@ async function removeFolder(folderId: string): Promise<void> {
6362
);
6463
for (const assoc of associationsToRemove) {
6564
if (assoc.worktree) {
66-
await deleteWorktreeIfExists(
67-
assoc.folderPath,
68-
assoc.worktree.worktreePath,
69-
);
65+
try {
66+
const worktreeBasePath = getWorktreeLocation();
67+
const manager = new WorktreeManager({
68+
mainRepoPath: assoc.folderPath,
69+
worktreeBasePath,
70+
});
71+
await manager.deleteWorktree(assoc.worktree.worktreePath);
72+
} catch (error) {
73+
log.error(
74+
`Failed to delete worktree ${assoc.worktree.worktreePath}:`,
75+
error,
76+
);
77+
}
7078
}
7179
}
7280

apps/array/src/main/services/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@ import "./settingsStore.js";
1212
import "./shell.js";
1313
import "./transcription-prompts.js";
1414
import "./updates.js";
15-
import "./worktree.js";
16-
import "./worktreeUtils.js";

apps/array/src/main/services/workspace/workspaceService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { logger } from "../../lib/logger";
1919
import { foldersStore } from "../../utils/store";
2020
import type { FileWatcherService } from "../file-watcher/service.js";
2121
import { getWorktreeLocation } from "../settingsStore";
22-
import { deleteWorktreeIfExists } from "../worktreeUtils";
2322
import { loadConfig, normalizeScripts } from "./configLoader";
2423
import { cleanupWorkspaceSessions, ScriptRunner } from "./scriptRunner";
2524
import { buildWorkspaceEnv } from "./workspaceEnv";
@@ -688,7 +687,9 @@ export class WorkspaceService {
688687
}
689688

690689
try {
691-
await deleteWorktreeIfExists(mainRepoPath, worktreePath);
690+
const worktreeBasePath = getWorktreeLocation();
691+
const manager = new WorktreeManager({ mainRepoPath, worktreeBasePath });
692+
await manager.deleteWorktree(worktreePath);
692693
} catch (error) {
693694
log.error(`Failed to delete worktree for task ${taskId}:`, error);
694695
}

apps/array/src/main/services/worktree.ts

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

apps/array/src/main/services/worktreeUtils.ts

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

apps/array/src/main/utils/store.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import path from "node:path";
2+
import { WorktreeManager } from "@posthog/agent";
23
import { app } from "electron";
34
import Store from "electron-store";
45
import type {
56
RegisteredFolder,
67
TaskFolderAssociation,
78
} from "../../shared/types";
8-
import { deleteWorktreeIfExists } from "../services/worktreeUtils";
9+
import { logger } from "../lib/logger";
10+
import { getWorktreeLocation } from "../services/settingsStore";
911

1012
interface FoldersSchema {
1113
folders: RegisteredFolder[];
@@ -80,15 +82,25 @@ export const foldersStore = new Store<FoldersSchema>({
8082
},
8183
});
8284

85+
const log = logger.scope("store");
86+
8387
export async function clearAllStoreData(): Promise<void> {
84-
// Delete all worktrees before clearing store
8588
const associations = foldersStore.get("taskAssociations", []);
8689
for (const assoc of associations) {
8790
if (assoc.worktree) {
88-
await deleteWorktreeIfExists(
89-
assoc.folderPath,
90-
assoc.worktree.worktreePath,
91-
);
91+
try {
92+
const worktreeBasePath = getWorktreeLocation();
93+
const manager = new WorktreeManager({
94+
mainRepoPath: assoc.folderPath,
95+
worktreeBasePath,
96+
});
97+
await manager.deleteWorktree(assoc.worktree.worktreePath);
98+
} catch (error) {
99+
log.error(
100+
`Failed to delete worktree ${assoc.worktree.worktreePath}:`,
101+
error,
102+
);
103+
}
92104
}
93105
}
94106

0 commit comments

Comments
 (0)