From 11552cc0bda744672d872aedfbe3828dce7c5be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Mon, 24 Mar 2025 16:03:57 -0300 Subject: [PATCH] Git: reload index before reading it (#27386) This is one of the causes for race conditions, but isn't a specific bug fix by itself. Release Notes: - N/A Co-authored-by: Max Brunsfeld --- crates/git/src/repository.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 70e370adf9db5e9e32ac145fe5ed3ff5d0883c20..139e07901aeae6c8ddc5a63abb2304289eaae98f 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -476,12 +476,13 @@ impl GitRepository for RealGitRepository { let repo = self.repository.clone(); cx.background_spawn(async move { fn logic(repo: &git2::Repository, path: &RepoPath) -> Result> { - const STAGE_NORMAL: i32 = 0; - let index = repo.index()?; - // This check is required because index.get_path() unwraps internally :( check_path_to_repo_path_errors(path)?; + let mut index = repo.index()?; + index.read(false)?; + + const STAGE_NORMAL: i32 = 0; let oid = match index.get_path(path, STAGE_NORMAL) { Some(entry) if entry.mode != GIT_MODE_SYMLINK => entry.id, _ => return Ok(None),