From e925d2ec38a9b40be66a6e2ea72b5cddc109f0ea Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:27:13 +0000 Subject: [PATCH] Fix worktree trust not applied on window reuse (#46623) (cherry-pick to preview) (#46628) Cherry-pick of #46623 to preview ---- New workspace/window creates a different `WeakEntity` for the same path, which was not considered before. Closes https://github.com/zed-industries/zed/issues/46318 Release Notes: - Fixed worktree trust not applied in window reuse Co-authored-by: Kirill Bulatov --- crates/project/src/trusted_worktrees.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/project/src/trusted_worktrees.rs b/crates/project/src/trusted_worktrees.rs index fe6ba0c1d1731330b01af4241776ee4fa90e259b..70651987b22d53b71d9bf7458139812f2f5fcb30 100644 --- a/crates/project/src/trusted_worktrees.rs +++ b/crates/project/src/trusted_worktrees.rs @@ -302,6 +302,9 @@ impl TrustedWorktreesStore { self.restricted.get_mut(&weak_worktree_store) { restricted_worktrees.remove(worktree_id); + if restricted_worktrees.is_empty() { + self.restricted.remove(&weak_worktree_store); + } }; if let Some(worktree) = @@ -610,7 +613,8 @@ impl TrustedWorktreesStore { &mut self, cx: &mut Context, ) -> HashMap, HashSet> { - self.trusted_paths + let new_trusted_paths = self + .trusted_paths .iter() .filter_map(|(worktree_store, paths)| { let host = self.worktree_stores.get(&worktree_store)?.clone(); @@ -628,13 +632,16 @@ impl TrustedWorktreesStore { .collect::>(); Some((host, abs_paths)) }) - .chain(self.db_trusted_paths.clone()) + .chain(self.db_trusted_paths.drain()) .fold(HashMap::default(), |mut acc, (host, paths)| { acc.entry(host) .or_insert_with(HashSet::default) .extend(paths); acc - }) + }); + + self.db_trusted_paths = new_trusted_paths.clone(); + new_trusted_paths } fn add_worktree_store( @@ -643,6 +650,8 @@ impl TrustedWorktreesStore { remote_host: Option, cx: &mut Context, ) { + self.worktree_stores + .retain(|worktree_store, _| worktree_store.is_upgradable()); let weak_worktree_store = worktree_store.downgrade(); self.worktree_stores .insert(weak_worktree_store.clone(), remote_host.clone());