Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

git blame: ignore uncommitted files or repos without commits (#10685)

Thorsten Ball4f1861edb604
diff --git a/crates/git/src/blame.rs b/crates/git/src/blame.rs
index 54ff7f664ac..8eedefc6fe0 100644
--- a/crates/git/src/blame.rs
+++ b/crates/git/src/blame.rs
@@ -63,6 +63,9 @@ impl Blame {
}
}
+const GIT_BLAME_NO_COMMIT_ERROR: &'static str = "fatal: no such ref: HEAD";
+const GIT_BLAME_NO_PATH: &'static str = "fatal: no such path";
+
fn run_git_blame(
git_binary: &Path,
working_directory: &Path,
@@ -98,6 +101,10 @@ fn run_git_blame(
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
+ let trimmed = stderr.trim();
+ if trimmed == GIT_BLAME_NO_COMMIT_ERROR || trimmed.contains(GIT_BLAME_NO_PATH) {
+ return Ok(String::new());
+ }
return Err(anyhow!("git blame process failed: {}", stderr));
}