mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
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` <img width="1509" height="793" alt="Screenshot 2026-11-17 at 23 20 02" src="https://github.com/user-attachments/assets/663550fc-44d7-4a57-add4-c45415a73bb9" /> the fix: check git exit status first and report the write error only after that. after fix no error: <img width="1509" height="807" alt="Screenshot 2026-11-17 at 23 29 18" src="https://github.com/user-attachments/assets/f570f228-17c9-4149-93c9-5569cbfc751a" /> ## 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 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
df5cf7b718
commit
58be7923cf
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user