Compare commits

...
Author SHA1 Message Date
Julius Marminge 2d3263d69d Force-remove dirty git worktrees during orphan cleanup
- add optional `force` to remove-worktree contract and server git args
- pass `force: true` from sidebar orphaned worktree cleanup flow
- add integration test covering dirty worktree removal behavior
2026-02-19 00:07:09 -08:00
5 changed files with 35 additions and 3 deletions

No files matched your search

+26
View File
@@ -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 ──
+5 -1
View File
@@ -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,
+1
View File
@@ -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.";
+2 -2
View File
@@ -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);
+1
View File
@@ -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({