Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Force-remove dirty git worktrees during orphan cleanup
Julius Marminge58a8d653a8f1
diff --git a/apps/server/src/git.test.ts b/apps/server/src/git.test.tsindex bea0f3a97..1e01c6d26 100644--- a/apps/server/src/git.test.ts+++ b/apps/server/src/git.test.ts@@ -617,6 +617,32 @@ describe("git integration", () => {await removeGitWorktree({ cwd: tmp.path, path: wtPath });expect(existsSync(wtPath)).toBe(false);});++ it("removeGitWorktree force removes a dirty worktree", async () => {+ await using tmp = await makeTmpDir();+ await initRepoWithCommit(tmp.path);++ const wtPath = path.join(tmp.path, "wt-dirty-dir");+ const currentBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(+ (b) => b.current,+ )!.name;++ await createGitWorktree({+ cwd: tmp.path,+ branch: currentBranch,+ newBranch: "wt-dirty",+ path: wtPath,+ });+ expect(existsSync(wtPath)).toBe(true);++ await writeFile(path.join(wtPath, "README.md"), "dirty change\n");++ await expect(removeGitWorktree({ cwd: tmp.path, path: wtPath })).rejects.toThrow();+ expect(existsSync(wtPath)).toBe(true);++ await removeGitWorktree({ cwd: tmp.path, path: wtPath, force: true });+ expect(existsSync(wtPath)).toBe(false);+ });});// ── Full flow: local branch checkout ──diff --git a/apps/server/src/git.ts b/apps/server/src/git.tsindex 874c4f978..a9a7aa062 100644--- a/apps/server/src/git.ts+++ b/apps/server/src/git.ts@@ -546,7 +546,11 @@ export class GitCoreService {}async removeWorktree(input: GitRemoveWorktreeInput): Promise<void> {- const args = ["worktree", "remove", input.path] as const;+ const args = ["worktree", "remove"];+ if (input.force) {+ args.push("--force");+ }+ args.push(input.path);try {await executeGit(input.cwd, args, {timeoutMs: 15_000,diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 9f9b5f15b..71a6e02ce 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -331,6 +331,7 @@ export default function Sidebar() {await removeWorktreeMutation.mutateAsync({cwd: threadProject.cwd,path: orphanedWorktreePath,+ force: true,});} catch (error) {const message = error instanceof Error ? error.message : "Unknown error removing worktree.";diff --git a/apps/web/src/lib/gitReactQuery.ts b/apps/web/src/lib/gitReactQuery.tsindex cd39aed64..fc0c7160a 100644--- a/apps/web/src/lib/gitReactQuery.ts+++ b/apps/web/src/lib/gitReactQuery.ts@@ -173,11 +173,11 @@ export function gitRemoveWorktreeMutationOptions(input: {queryClient: QueryClient;}) {return mutationOptions({- mutationFn: async ({ cwd, path }: { cwd: string; path: string }) => {+ mutationFn: async ({ cwd, path, force }: { cwd: string; path: string; force?: boolean }) => {if (!input.api) {throw new Error("Git worktree removal is unavailable.");}- return input.api.git.removeWorktree({ cwd, path });+ return input.api.git.removeWorktree({ cwd, path, force });},onSettled: async () => {await invalidateGitQueries(input.queryClient);diff --git a/packages/contracts/src/git.ts b/packages/contracts/src/git.tsindex 5b275df1c..fad26b834 100644--- a/packages/contracts/src/git.ts+++ b/packages/contracts/src/git.ts@@ -16,6 +16,7 @@ export const gitCreateWorktreeInputSchema = z.object({export const gitRemoveWorktreeInputSchema = z.object({cwd: z.string().min(1),path: z.string().min(1),+ force: z.boolean().optional(),});export const gitCreateBranchInputSchema = z.object({