Skip to content

Clean up empty parent directory after archiving worktree#53671

Draft
rtfeldman wants to merge 3 commits intomainfrom
fix-archive-empty-parent-dir
Draft

Clean up empty parent directory after archiving worktree#53671
rtfeldman wants to merge 3 commits intomainfrom
fix-archive-empty-parent-dir

Conversation

@rtfeldman
Copy link
Copy Markdown
Contributor

@rtfeldman rtfeldman commented Apr 11, 2026

Zed creates worktrees at <worktrees_dir>/<branch_name>/<project_name>/. When git worktree remove deletes the inner project directory, the intermediate branch-name directory is left behind as an empty folder on disk.

After a successful git worktree remove, this now checks if the parent directory is empty AND is inside Zed's managed worktrees directory (from the git.worktree_directory setting). If both conditions are met, the empty parent is removed. Directories outside the managed worktrees directory are never touched, so user-created worktrees at custom paths won't have their parent directories deleted.

Release Notes:

  • Fixed empty parent directories being left behind after archiving a thread that used a linked git worktree.

Zed creates worktrees inside an intermediate directory named after
the branch: <worktrees_dir>/<branch_name>/<project_name>/. When
git worktree remove deletes the inner project directory, the branch
directory is left behind as an empty directory. After a successful
git worktree remove, check if the parent directory is now empty and
remove it if so.
Zed creates worktrees at <worktrees_dir>/<branch_name>/<project_name>/.
When git worktree remove deletes the inner project directory, the
intermediate branch directory is left behind as an empty folder.

After a successful git worktree remove, check if the parent directory
is now empty AND is inside Zed's managed worktrees directory (from
the git.worktree_directory setting). If both conditions are met,
remove the empty parent. Directories outside the managed worktrees
directory are never touched, so user-created worktrees at custom
paths won't have their parent directories deleted.
@rtfeldman rtfeldman self-assigned this Apr 11, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 11, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant