From de4640f23fb5300437a0633da2fd209f270486e8 Mon Sep 17 00:00:00 2001 From: "deeraj.chowdary" Date: Sat, 23 Aug 2025 13:24:03 +0530 Subject: [PATCH] fix : repo changes automatically with change in file buffer --- crates/project/src/git_store.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index 5cf298a8bf..a7cf83698a 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -448,6 +448,31 @@ 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(worktree) = self + .worktree_store + .read(cx) + .worktree_for_id(project_path.worktree_id, cx) + { + let abs_file_path = worktree + .read(cx) + .abs_path() + .join(project_path.path.as_ref()); + + for (id, repo) in &self.repositories { + let repo_path = repo.read(cx).work_directory_abs_path.clone(); + if abs_file_path.starts_with(&repo_path) { + if self.active_repo_id != Some(*id) { + self.active_repo_id = Some(*id); + cx.emit(GitStoreEvent::ActiveRepositoryChanged(Some(*id))); + } + return; + } + } + } + + } + pub fn shared(&mut self, project_id: u64, client: AnyProtoClient, cx: &mut Context) { match &mut self.state { @@ -1134,7 +1159,6 @@ impl GitStore { _ => {} } } - fn on_repository_event( &mut self, repo: Entity, @@ -1292,6 +1316,10 @@ impl GitStore { diffs.remove(buffer_id); } } + BufferStoreEvent::BufferOpened { project_path, .. } => { + self.set_active_repo_for_path(project_path, cx); + } + _ => {} }