Skip to content

Worktree deletion fails with 'Directory not empty' error when metadata is inconsistent #14435

Closed

Description

@yinyuncan

问题描述

在尝试删除 worktree 时遇到错误:

Error invoking remote method 'worktrees:remove': Error: Failed to force delete worktree at /Volumes/kioxia/yuncan/orca/workspaces/onorca-docs-cn/margate. error: failed to delete '/Volumes/kioxia/yuncan/orca/workspaces/onorca-docs-cn/margate': Directory not empty

复现步骤

  1. 创建一个 worktree
  2. 在 worktree 中进行工作(安装依赖、生成文件等)
  3. 尝试通过 Orca UI 删除该 worktree

预期行为

Worktree 应该被成功删除,即使目录中包含文件

实际行为

删除失败,提示 "Directory not empty"

根本原因分析

通过调查发现:

  • Git worktree 元数据(.git/worktrees/<name>)已被清理
  • 但物理工作目录仍然存在且包含大量文件(如 node_modules、构建产物等)
  • Git 分支引用残留在 .git/refs/heads/<name>
  • git worktree remove 命令无法处理这种不一致状态

临时解决方案

需要手动清理:

# 1. 删除物理目录
rm -rf /path/to/worktree

# 2. 删除残留的 Git 分支
cd /path/to/main/repo
git branch -D <branch-name>

建议修复方案

  1. 增强错误处理:当 worktree 元数据与物理目录状态不一致时,应该先检测并清理物理目录
  2. 强制删除选项:在删除失败时,提供一个"强制删除"选项,直接删除物理目录并清理 Git 引用
  3. 状态检查:在删除前检查 worktree 状态,如果发现不一致,自动执行清理流程

环境信息

  • OS: macOS
  • Orca 版本: [请填写您的版本]
  • Git 版本: [通过 git --version 获取]

影响

用户需要手动清理,这对不熟悉 Git worktree 机制的用户来说比较困难。

Activity

  1. goransh-walia commented on Aug 14, 2026

    @goransh-walia

    This would be a genuinely useful fix/addition for the project.

  2. AmethystLiang commented on Aug 14, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  3. added
    bugSomething isn't working
    os:macosIssues affecting macOS
    on Sep 19, 2026
  4. added theissue type on Sep 19, 2026
  5. AmoabaKelvin commented on Nov 17, 2026

    @AmoabaKelvin
    Collaborator

    Fixed by #33209: Orca now finishes a delete that git left half-done, so the 'Directory not empty' failure no longer blocks removal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggitos:macosIssues affecting macOS

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions