diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index d06fc37288a4a98087e39521016552e0e850be1b..5b718ce68984a82fcbe207c67e37b374caa3417a 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -439,6 +439,15 @@ impl GitStore { pub fn is_local(&self) -> bool { matches!(self.state, GitStoreState::Local { .. }) } + pub fn set_active_repo_for_path(&mut self, project_path: &ProjectPath, cx: &mut Context) { + if let Some((repo, _)) = self.repository_and_path_for_project_path(project_path, cx) { + let id = repo.read(cx).id; + if self.active_repo_id != Some(id) { + self.active_repo_id = Some(id); + cx.emit(GitStoreEvent::ActiveRepositoryChanged(Some(id))); + } + } + } pub fn shared(&mut self, project_id: u64, client: AnyProtoClient, cx: &mut Context) { match &mut self.state { @@ -1111,7 +1120,6 @@ impl GitStore { _ => {} } } - fn on_repository_event( &mut self, repo: Entity, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index a5487411983c01c5e26ea349a3c3c0c23e408554..14088d95d7d086c5dde46209a3d4a07cbf7b1f79 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -4400,8 +4400,16 @@ impl Workspace { fn active_item_path_changed(&mut self, window: &mut Window, cx: &mut Context) { cx.emit(Event::ActiveItemChanged); let active_entry = self.active_project_path(cx); - self.project - .update(cx, |project, cx| project.set_active_path(active_entry, cx)); + self.project.update(cx, |project, cx| { + project.set_active_path(active_entry.clone(), cx) + }); + + if let Some(project_path) = &active_entry { + let git_store_entity = self.project.read(cx).git_store().clone(); + git_store_entity.update(cx, |git_store, cx| { + git_store.set_active_repo_for_path(project_path, cx); + }); + } self.update_window_title(window, cx); }