From dd7eced2b6114458bd1d084938346ccee2d82862 Mon Sep 17 00:00:00 2001 From: Jason Wen <107383260+the-jasoney@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:02:24 -0700 Subject: [PATCH] Prevent command prompt from opening when running git blame on windows (#10747) Release Notes: - Fixed issue reported in discord where the git blame feature would open command prompt windows --- Cargo.lock | 1 + crates/git/Cargo.toml | 1 + crates/git/src/blame.rs | 14 ++++++++++++-- crates/git/src/commit.rs | 14 ++++++++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fdb1501f3deff459c6b6d954bf798224ca24eb3..7468b5374131519752435f8a627b282cb856784d 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.toml index d17dc7aa2a5be3ea77e055a73de0313349554d18..c839ee069e438a80b57584597f65a33cda414afc 100644 --- a/crates/git/Cargo.toml +++ b/crates/git/Cargo.toml @@ -24,6 +24,7 @@ text.workspace = true time.workspace = true url.workspace = true serde.workspace = true +windows.workspace = true [dev-dependencies] unindent.workspace = true diff --git a/crates/git/src/blame.rs b/crates/git/src/blame.rs index d16915174d251908b91ca2757cd536965e8bb5a8..bb86cb4275b5b212cb27dcabbfda6b029ec2d629 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 { - 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.rs index ad7aeb48f2c78f9f6e740078e95ca641c68d4c5c..5a3aaccae697e0d17d7ddbef57d3c147b41a24f2 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> { const MARKER: &'static str = ""; - 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))?;