fix : repo changes automatically with change in file buffer

This commit is contained in:
deeraj.chowdary 2025-08-23 13:24:03 +05:30
parent ed84767c9d
commit de4640f23f

View file

@ -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<Self>) {
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<Self>) {
match &mut self.state {
@ -1134,7 +1159,6 @@ impl GitStore {
_ => {}
}
}
fn on_repository_event(
&mut self,
repo: Entity<Repository>,
@ -1292,6 +1316,10 @@ impl GitStore {
diffs.remove(buffer_id);
}
}
BufferStoreEvent::BufferOpened { project_path, .. } => {
self.set_active_repo_for_path(project_path, cx);
}
_ => {}
}