From bf25cb1835ae03c26c778646e01bc634ae690a59 Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Wed, 15 Apr 2026 15:25:07 -0400 Subject: [PATCH] agent: Inline worktree info fetching to remove expects in agent_panel (#54006) The `worktree_receivers` and `worktree_directory_setting` were pre computed as `Option`s before the async block, then unwrapped with `expect` inside the match arm that always had them set. Move the fetching directly into the `WorktreeCreationArgs::New` arm so the values are never optional, replacing the panicking expects with error propagation via `?`. The expects were guaranteed to never panic because the `Some` codepath used the same branching logic of the unwrap codepath later on. This change is just for future maintainability though. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - N/A or Added/Fixed/Improved ... --- crates/agent_ui/src/agent_panel.rs | 36 ++++++++++-------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 413bad667825f05ad6b399677877fb2ec99cb7c9..5bb994dadf407e018b3be1ad6fe5d33ef0ed5a23 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -3258,26 +3258,6 @@ impl AgentPanel { return; } - let (worktree_receivers, worktree_directory_setting) = - if matches!(args, WorktreeCreationArgs::New { .. }) { - ( - Some( - git_repos - .iter() - .map(|repo| repo.update(cx, |repo, _cx| repo.worktrees())) - .collect::>(), - ), - Some( - ProjectSettings::get_global(cx) - .git - .worktree_directory - .clone(), - ), - ) - } else { - (None, None) - }; - let remote_connection_options = self.project.read(cx).remote_connection_options(cx); if remote_connection_options.is_some() { @@ -3314,10 +3294,18 @@ impl AgentPanel { worktree_name, branch_target, } => { - let worktree_receivers = worktree_receivers - .expect("worktree receivers must be prepared for new worktree creation"); - let worktree_directory_setting = worktree_directory_setting - .expect("worktree directory must be prepared for new worktree creation"); + let worktree_receivers: Vec<_> = this.update_in(cx, |_this, _window, cx| { + git_repos + .iter() + .map(|repo| repo.update(cx, |repo, _cx| repo.worktrees())) + .collect() + })?; + let worktree_directory_setting = this.update_in(cx, |_this, _window, cx| { + ProjectSettings::get_global(cx) + .git + .worktree_directory + .clone() + })?; let mut existing_worktree_names = Vec::new(); let mut existing_worktree_paths = HashSet::default();