git: Don't show console on Windows

When used inside GUI application, git.subprocess=true option causes console window to appear temporarily.

std::process::Command needs special flags to prevent that. More details: https://stackoverflow.com/a/60958956
This commit is contained in:
Fedor Sheremetyev 2025-03-08 10:42:37 +00:00 committed by Philip Metzger
parent bdbb7afbbb
commit a028e4a03a

View file

@ -105,6 +105,14 @@ impl<'a> GitSubprocessContext<'a> {
/// Create the Git command
fn create_command(&self) -> Command {
let mut git_cmd = Command::new(self.git_executable_path);
// Hide console window on Windows (https://stackoverflow.com/a/60958956)
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
git_cmd.creation_flags(CREATE_NO_WINDOW);
}
// TODO: here we are passing the full path to the git_dir, which can lead to UNC
// bugs in Windows. The ideal way to do this is to pass the workspace
// root to Command::current_dir and then pass a relative path to the git