( projectPath: string, worktreePath: string )
| 31 | } |
| 32 | |
| 33 | export 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 | } |
no test coverage detected