From 087594c226d0e38163e18eee76123f8e332130f2 Mon Sep 17 00:00:00 2001 From: Fedor Sheremetyev Date: Sat, 10 Aug 2024 17:20:21 +0100 Subject: [PATCH 1/4] Don't show console on Windows When used inside GUI application, gix causes console window to appear temporarily, due to execution of git. Command needs special flags to prevent that. More details: https://stackoverflow.com/a/60958956 --- gix-path/src/env/git/mod.rs | 6 ++++++ gix-path/src/env/mod.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/gix-path/src/env/git/mod.rs b/gix-path/src/env/git/mod.rs index 9ba82d6c027..a24e26ecb47 100644 --- a/gix-path/src/env/git/mod.rs +++ b/gix-path/src/env/git/mod.rs @@ -82,6 +82,12 @@ pub(super) static EXE_NAME: &str = "git"; pub(super) static EXE_INFO: Lazy> = Lazy::new(|| { let git_cmd = |executable: PathBuf| { let mut cmd = Command::new(executable); + #[cfg(windows)] + { + use std::os::windows::process::CommandExt; + const CREATE_NO_WINDOW: u32 = 0x08000000; + cmd.creation_flags(CREATE_NO_WINDOW); + } cmd.args(["config", "-l", "--show-origin"]) .stdin(Stdio::null()) .stderr(Stdio::null()); diff --git a/gix-path/src/env/mod.rs b/gix-path/src/env/mod.rs index 0e528058e9b..154a0d1ddfa 100644 --- a/gix-path/src/env/mod.rs +++ b/gix-path/src/env/mod.rs @@ -109,6 +109,12 @@ pub fn system_prefix() -> Option<&'static Path> { } let mut cmd = std::process::Command::new(exe_invocation()); + #[cfg(windows)] + { + use std::os::windows::process::CommandExt; + const CREATE_NO_WINDOW: u32 = 0x08000000; + cmd.creation_flags(CREATE_NO_WINDOW); + } cmd.arg("--exec-path").stderr(std::process::Stdio::null()); gix_trace::debug!(cmd = ?cmd, "invoking git to get system prefix/exec path"); let path = cmd.output().ok()?.stdout; From f6cd9191af9d80cd5a1c37a58d4879451c8faddc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 10 Aug 2024 20:04:01 +0200 Subject: [PATCH 2/4] fix: prevent the popup of terminal Windows on any command invocation. --- gix-command/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gix-command/src/lib.rs b/gix-command/src/lib.rs index e5437c552ed..7e028e1baa2 100644 --- a/gix-command/src/lib.rs +++ b/gix-command/src/lib.rs @@ -237,6 +237,13 @@ mod prepare { } else { Command::new(prep.command) }; + // We never want to have terminals pop-up on Windows if this runs from a GUI application. + #[cfg(windows)] + { + use std::os::windows::process::CommandExt; + const CREATE_NO_WINDOW: u32 = 0x08000000; + cmd.creation_flags(CREATE_NO_WINDOW); + } cmd.stdin(prep.stdin) .stdout(prep.stdout) .stderr(prep.stderr) @@ -401,6 +408,8 @@ pub mod shebang { /// - `stdout` is captured for consumption by the caller /// - `stderr` is inherited to allow the command to provide context to the user /// +/// On Windows, terminal Windows will be suppressed automatically. +/// /// ### Warning /// /// When using this method, be sure that the invoked program doesn't rely on the current working dir and/or From 1257fbdd0f54eafde2546f2140e945d11fb0eb6a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 10 Aug 2024 20:14:31 +0200 Subject: [PATCH 3/4] fix: prevent terminal windows from popping up if code is run from a graphical UI on Windows --- .../attributes/validate_baseline.rs | 30 ++++++++++--------- gitoxide-core/src/repository/commit.rs | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gitoxide-core/src/repository/attributes/validate_baseline.rs b/gitoxide-core/src/repository/attributes/validate_baseline.rs index 82b69c82ef6..85524e9bda6 100644 --- a/gitoxide-core/src/repository/attributes/validate_baseline.rs +++ b/gitoxide-core/src/repository/attributes/validate_baseline.rs @@ -74,13 +74,14 @@ pub(crate) mod function { let tx_base = tx_base.clone(); let mut progress = progress.add_child("attributes"); move || -> anyhow::Result<()> { - let mut child = std::process::Command::new(gix::path::env::exe_invocation()) - .args(["check-attr", "--stdin", "-a"]) - .stdin(std::process::Stdio::piped()) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::null()) - .current_dir(path) - .spawn()?; + let mut child = + std::process::Command::from(gix::command::prepare(gix::path::env::exe_invocation())) + .args(["check-attr", "--stdin", "-a"]) + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::null()) + .current_dir(path) + .spawn()?; std::thread::spawn({ let mut stdin = child.stdin.take().expect("we configured it"); @@ -125,13 +126,14 @@ pub(crate) mod function { let tx_base = tx_base.clone(); let mut progress = progress.add_child("excludes"); move || -> anyhow::Result<()> { - let mut child = std::process::Command::new(gix::path::env::exe_invocation()) - .args(["check-ignore", "--stdin", "-nv", "--no-index"]) - .stdin(std::process::Stdio::piped()) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::null()) - .current_dir(path) - .spawn()?; + let mut child = + std::process::Command::from(gix::command::prepare(gix::path::env::exe_invocation())) + .args(["check-ignore", "--stdin", "-nv", "--no-index"]) + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::null()) + .current_dir(path) + .spawn()?; std::thread::spawn({ let mut stdin = child.stdin.take().expect("we configured it"); diff --git a/gitoxide-core/src/repository/commit.rs b/gitoxide-core/src/repository/commit.rs index e0070dc2ae3..e7b920a357b 100644 --- a/gitoxide-core/src/repository/commit.rs +++ b/gitoxide-core/src/repository/commit.rs @@ -20,7 +20,7 @@ pub fn verify(repo: gix::Repository, rev_spec: Option<&str>) -> Result<()> { signature_storage.write_all(signature.as_ref())?; let signed_storage = signature_storage.into_temp_path(); - let mut cmd = std::process::Command::new("gpg"); + let mut cmd: std::process::Command = gix::command::prepare("gpg").into(); cmd.args(["--keyid-format=long", "--status-fd=1", "--verify"]) .arg(&signed_storage) .arg("-") From cacc8af96a41e601c5136cba4b1f9b3b9d5e6844 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 10 Aug 2024 20:18:07 +0200 Subject: [PATCH 4/4] fix: prevent terminal Windows to popup on Windows when run from a GUI application. --- gix-credentials/src/program/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gix-credentials/src/program/mod.rs b/gix-credentials/src/program/mod.rs index 5f705f93b5e..9aa7aed0aac 100644 --- a/gix-credentials/src/program/mod.rs +++ b/gix-credentials/src/program/mod.rs @@ -71,7 +71,7 @@ impl Program { let git_program = gix_path::env::exe_invocation(); let mut cmd = match &self.kind { Kind::Builtin => { - let mut cmd = Command::new(git_program); + let mut cmd = Command::from(gix_command::prepare(git_program)); cmd.arg("credential").arg(action.as_arg(false)); cmd }