diff --git a/crates/git/src/blame.rs b/crates/git/src/blame.rs index c4dfe9602ae..a7872d51375 100644 --- a/crates/git/src/blame.rs +++ b/crates/git/src/blame.rs @@ -178,8 +178,13 @@ async fn run_git_blame( .context("waiting for git blame process") }; - let ((), entries, stderr, status) = - try_join!(write_stdin, read_stdout, read_stderr, wait_for_status)?; + // Git closes stdin when it exits early, so its status is checked before the write error. + let (write_result, entries, stderr, status) = try_join!( + async { anyhow::Ok(write_stdin.await) }, + read_stdout, + read_stderr, + wait_for_status + )?; if !status.success() { let trimmed = stderr.trim(); @@ -188,6 +193,7 @@ async fn run_git_blame( } anyhow::bail!("git blame process failed: {stderr}"); } + write_result.context("writing contents to git blame")?; Ok(entries) } diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index e08c0019a69..8c9b3350e53 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -5931,6 +5931,36 @@ mod tests { ); } + #[gpui::test] + async fn test_blame_untracked_path_with_large_contents(cx: &mut TestAppContext) { + disable_git_global_config(); + cx.executor().allow_parking(); + + let repo_dir = tempfile::tempdir().unwrap(); + git_init_repo(repo_dir.path()); + fs::write(repo_dir.path().join("committed.txt"), "line one\n").unwrap(); + git_command(repo_dir.path(), ["add", "-A"]); + git_command(repo_dir.path(), ["commit", "-m", "First commit"]); + let repo = RealGitRepository::new( + &repo_dir.path().join(".git"), + None, + Some("git".into()), + cx.executor(), + ) + .unwrap(); + + // Git exits without reading stdin for a path that isn't in HEAD. + let blame = repo + .blame( + repo_path("untracked.txt"), + Rope::from("line\n".repeat(1 << 20)), + LineEnding::Unix, + ) + .await + .unwrap(); + assert_eq!(blame.entries, Vec::new()); + } + #[gpui::test] async fn test_branches_return_head_when_commit_metadata_cannot_be_read( cx: &mut TestAppContext,