MCPcopy
hub / github.com/coder/mux / removeManagedGitWorktree

Function removeManagedGitWorktree

src/node/worktree/removeManagedGitWorktree.ts:33–69  ·  view source on GitHub ↗
(
  projectPath: string,
  worktreePath: string
)

Source from the content-addressed store, hash-verified

31}
32
33export async function removeManagedGitWorktree(
34 projectPath: string,
35 worktreePath: string
36): Promise<void> {
37 if (!(await worktreePathExists(worktreePath))) {
38 await pruneWorktreesBestEffort(projectPath);
39 return;
40 }
41
42 try {
43 using removeProc = execFileAsync(
44 "git",
45 ["-C", projectPath, "worktree", "remove", "--force", worktreePath],
46 {
47 env: GIT_NO_HOOKS_ENV,
48 }
49 );
50 await removeProc.result;
51 } catch (error) {
52 const errorMessage = getErrorMessage(error);
53 const worktreeStillExists = await worktreePathExists(worktreePath);
54
55 if (!worktreeStillExists) {
56 if (!isMissingWorktreeError(errorMessage)) {
57 throw error;
58 }
59
60 await pruneWorktreesBestEffort(projectPath);
61 return;
62 }
63
64 // Multi-project workspaces persist a _workspaces/<name> container here instead of a git
65 // worktree root, so we still need recursive removal after git worktree remove rejects it.
66 await fsPromises.rm(worktreePath, { recursive: true, force: true });
67 await pruneWorktreesBestEffort(projectPath);
68 }
69}

Callers 3

deleteWorktreeMethod · 0.90

Calls 5

execFileAsyncFunction · 0.90
getErrorMessageFunction · 0.90
worktreePathExistsFunction · 0.85
pruneWorktreesBestEffortFunction · 0.85
isMissingWorktreeErrorFunction · 0.85

Tested by

no test coverage detected