Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Prevent command prompt from opening when running git blame on windows (#10747)
Jason Wendd7eced2b611
diff --git a/Cargo.lock b/Cargo.lockindex 3fdb1501f3d..7468b537413 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4327,6 +4327,7 @@ dependencies = ["time","unindent","url",+ "windows 0.53.0",][[package]]diff --git a/crates/git/Cargo.toml b/crates/git/Cargo.tomlindex d17dc7aa2a5..c839ee069e4 100644--- a/crates/git/Cargo.toml+++ b/crates/git/Cargo.toml@@ -24,6 +24,7 @@ text.workspace = truetime.workspace = trueurl.workspace = trueserde.workspace = true+windows.workspace = true[dev-dependencies]unindent.workspace = truediff --git a/crates/git/src/blame.rs b/crates/git/src/blame.rsindex d16915174d2..bb86cb4275b 100644--- a/crates/git/src/blame.rs+++ b/crates/git/src/blame.rs@@ -14,6 +14,9 @@ use time::OffsetDateTime;use time::UtcOffset;use url::Url;+#[cfg(windows)]+use std::os::windows::process::CommandExt;+pub use git2 as libgit;#[derive(Debug, Clone, Default)]@@ -76,7 +79,9 @@ fn run_git_blame(path: &Path,contents: &Rope,) -> Result<String> {- let child = Command::new(git_binary)+ let mut child = Command::new(git_binary);++ child.current_dir(working_directory).arg("blame").arg("--incremental")@@ -85,7 +90,12 @@ fn run_git_blame(.arg(path.as_os_str()).stdin(Stdio::piped()).stdout(Stdio::piped())- .stderr(Stdio::piped())+ .stderr(Stdio::piped());++ #[cfg(windows)]+ child.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);++ let child = child.spawn().map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;diff --git a/crates/git/src/commit.rs b/crates/git/src/commit.rsindex ad7aeb48f2c..5a3aaccae69 100644--- a/crates/git/src/commit.rs+++ b/crates/git/src/commit.rs@@ -4,15 +4,25 @@ use collections::HashMap;use std::path::Path;use std::process::Command;+#[cfg(windows)]+use std::os::windows::process::CommandExt;+pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oid, String>> {const MARKER: &'static str = "<MARKER>";- let output = Command::new("git")+ let mut command = Command::new("git");++ command.current_dir(working_directory).arg("show").arg("-s").arg(format!("--format=%B{}", MARKER))- .args(shas.iter().map(ToString::to_string))+ .args(shas.iter().map(ToString::to_string));++ #[cfg(windows)]+ command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);++ let output = command.output().map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;