# Skip git worktree removal when archiving threads on main worktrees \(\#53629\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/5f2373b7b11abe9c7962a96123edf6b7db79fded)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 5f2373b7b11abe9c7962a96123edf6b7db79fded

Requested commit: 5f2373b7b11abe9c7962a96123edf6b7db79fded

Commit: 5f2373b7b11abe9c7962a96123edf6b7db79fded

Tree: f57b07394e9567661d92a989bf7189494a4c4b25

Author: Richard Feldman

Committer: GitHub

## Message

````
Skip git worktree removal when archiving threads on main worktrees (#53629)

When archiving a thread that lives on a main worktree (not a linked
worktree), `build_root_plan` was still returning a `RootPlan`, which
caused the archive flow to call `git worktree remove` on the main
working tree. Git rightfully refuses this with:

```
fatal: '/Users/rtfeldman/code/zed' is a main working tree
```

This fix makes `build_root_plan` return `None` for non-linked worktrees,
so the archive-to-disk machinery is simply skipped. The thread is marked
archived in the metadata store and can be unarchived later — no git
operations needed.

Since `build_root_plan` now guarantees a linked worktree when it returns
`Some`, `RootPlan::worktree_repo` is tightened from
`Option<Entity<Repository>>` to `Entity<Repository>`, removing the
fallback codepath and the `is_some()` guard in `archive_worktree_roots`.

Release Notes:

- Fixed a crash when archiving an agent thread that was opened on the
main project (not a linked git worktree).
````

## Parents

- [1150c9d6640933f41a4e57eb67c5ec503ba8f4bb](https://git.cafe/gitcafe/zed/commit/1150c9d6640933f41a4e57eb67c5ec503ba8f4bb?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/5f2373b7b11abe9c7962a96123edf6b7db79fded?format=markdown)
