Skip to content

Commit

Permalink
Don't show console on Windows
Browse files Browse the repository at this point in the history
When used inside GUI application, git2 causes console window to appear temporarily, due to execution of sh.

Command needs special flags to prevent that. More details: https://stackoverflow.com/a/60958956
  • Loading branch information
sheremetyev committed Aug 11, 2024
1 parent cfe2cd3 commit 4e763c7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ impl CredentialHelper {
// If that fails then it's up to the user to put `sh` in path and make
// sure it works.
let mut c = Command::new("sh");
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
c.creation_flags(CREATE_NO_WINDOW);
}
c.arg("-c")
.arg(&format!("{} get", cmd))
.stdin(Stdio::piped())
Expand All @@ -384,6 +390,12 @@ impl CredentialHelper {
debug!("`sh` failed to spawn: {}", e);
let mut parts = cmd.split_whitespace();
let mut c = Command::new(parts.next().unwrap());
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
c.creation_flags(CREATE_NO_WINDOW);
}
for arg in parts {
c.arg(arg);
}
Expand Down

0 comments on commit 4e763c7

Please sign in to comment.