From 58be7923cfef5964a0c24cbcffff24574d1117c0 Mon Sep 17 00:00:00 2001 From: Dmytro Danilenkov <63580205+dmytrodanilenkov@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:29:57 +0000 Subject: [PATCH] git: Fix broken pipe error when blaming large untracked files (#67110) ## Summary Split out of #66953. Zed runs `git blame --contents -` and writes the buffer text into git's stdin. when the file is not in HEAD (new or untracked), git exits without reading stdin. if the buffer is over 64KB (checked on my macOS) the write fails with `Broken pipe` and Zed returns that error instead of empty blame. I guess on Linux it will also fail because 64 KB is default pipe size. steps to reproduce: 1. In git repository create an untracked file larger than 64 KB and open it in Zed. 2. cmd+shift+p(macOS) and select "Run editor: toggle git blame" 3. On main you should get an error toast containing `Broken pipe` Screenshot 2026-11-17 at 23 20 02 the fix: check git exit status first and report the write error only after that. after fix no error: Screenshot 2026-11-17 at 23 29 18 ## Testing manually tested, no broken pipe error. Added `test_blame_untracked_path_with_large_contents`. On `main` it fails with `Broken pipe (os error 32)`; with this change it passes. Ran the `git` crate tests on macOS. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] N/A UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - Fixed git blame failing with a broken pipe error for large untracked files. Co-authored-by: Claude Fable 5.2 --- crates/git/src/blame.rs | 10 ++++++++-- crates/git/src/repository.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) 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,