Forget unmanaged orphan worktrees safely

This commit is contained in:
Bohdan Triapitsyn
2026-06-12 18:36:06 +03:00
parent ea3bb103eb
commit 782bc92b15
2 changed files with 5 additions and 6 deletions
+3 -4
View File
@@ -3680,12 +3680,11 @@ export async function removeWorktree(directory, input = {}) {
})();
if (!matchedEntry?.worktree) {
if (targetCanonical === worktreeRootCanonical || !isInsideOrSameDirectory(worktreeRootCanonical, targetCanonical)) {
throw new Error('Cannot remove unmanaged worktree directory');
}
const isManagedOrphan = targetCanonical !== worktreeRootCanonical
&& isInsideOrSameDirectory(worktreeRootCanonical, targetCanonical);
const targetExists = await checkPathExists(targetDirectory);
if (targetExists) {
if (targetExists && isManagedOrphan) {
await fsp.rm(targetDirectory, { recursive: true, force: true });
}