Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project: Change Git repo automatically with change in file buffer (#36796)
rufeveand8698dffe36b
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rsindex d06fc37288a..5b718ce6898 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<Self>) {+ 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<Self>) {match &mut self.state {@@ -1111,7 +1120,6 @@ impl GitStore {_ => {}}}-fn on_repository_event(&mut self,repo: Entity<Repository>,diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex a5487411983..14088d95d7d 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<Self>) {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);}