From 841d1a41b7b3bef489ff2b183be374413b3a93e6 Mon Sep 17 00:00:00 2001 From: Christoph Brandau Date: Tue, 30 Jun 2026 19:17:17 +0200 Subject: [PATCH] Suppress Git console window on Windows When executing Git commands on Windows, a console window would briefly flash. This change applies the CREATE_NO_WINDOW flag to prevent this, providing a smoother user experience. --- src-tauri/src/git.rs | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src-tauri/src/git.rs b/src-tauri/src/git.rs index 1d5bf52..7f36f5c 100644 --- a/src-tauri/src/git.rs +++ b/src-tauri/src/git.rs @@ -12,6 +12,12 @@ use std::{ time::Duration, }; +#[cfg(windows)] +use std::os::windows::process::CommandExt; + +#[cfg(windows)] +const CREATE_NO_WINDOW: u32 = 0x08000000; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "lowercase")] pub enum FileStatusKind { @@ -143,6 +149,13 @@ const EMPTY_TREE_HASH: &str = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; const SEARCH_CANCELLED_MESSAGE: &str = "Suche wurde abgebrochen."; static CANCELLABLE_GIT_OUTPUT_COUNTER: AtomicU64 = AtomicU64::new(0); +fn git_command() -> Command { + let mut command = Command::new("git"); + #[cfg(windows)] + command.creation_flags(CREATE_NO_WINDOW); + command +} + #[derive(Debug, Default, Clone)] pub struct SearchCancellationState { cancelled: Arc>>, @@ -342,7 +355,7 @@ pub fn pull( (Some(u), Some(p)) if !u.is_empty() || !p.is_empty() => { run_git_authenticated_output(&repo, pull_args, u, p)? } - _ => Command::new("git") + _ => git_command() .arg("-C") .arg(&repo) .args(pull_args) @@ -429,7 +442,7 @@ pub fn get_remote_url(path: String) -> Result, String> { } fn remote_url_for(repo: &Path, remote: &str) -> Option { - let out = Command::new("git") + let out = git_command() .arg("-C") .arg(repo) .args(["remote", "get-url", remote]) @@ -452,7 +465,7 @@ fn upstream_remote_name(repo: &Path) -> Option { if branch.is_empty() || branch == "HEAD" { return None; } - let out = Command::new("git") + let out = git_command() .arg("-C") .arg(repo) .args(["config", &format!("branch.{branch}.remote")]) @@ -530,7 +543,7 @@ pub fn merge_branch(path: String, branch: String) -> Result { return Err("Branch-Name darf nicht leer sein.".to_string()); } - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(&repo) .args(["merge", "--no-edit", branch]) @@ -1106,7 +1119,7 @@ fn is_binary_bytes(bytes: &[u8]) -> bool { fn index_stage_size(repo: &Path, stage: u8, file: &str) -> Option { let spec = format!(":{stage}:{file}"); - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(repo) .args(["cat-file", "-s", spec.as_str()]) @@ -1139,7 +1152,7 @@ pub fn resolve_conflict(path: String, file: String, content: String) -> Result Option { let spec = format!(":{stage}:{file}"); - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(repo) .args(["show", spec.as_str()]) @@ -1369,7 +1382,7 @@ fn max_parent_match_count( fn read_text_blob(repo: &Path, commit: &str, file: &str) -> Result, String> { let spec = format!("{commit}:{file}"); - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(repo) .args(["show", spec.as_str()]) @@ -1823,7 +1836,7 @@ fn local_branch_name_for_remote(remote_branch: &str) -> Option<&str> { } fn ref_exists(repo: &Path, ref_name: &str) -> Result { - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(repo) .args(["show-ref", "--verify", "--quiet", ref_name]) @@ -2048,7 +2061,7 @@ where { let askpass = write_askpass_script()?; - let result = Command::new("git") + let result = git_command() .arg("-C") .arg(repo) .args(args) @@ -2157,7 +2170,7 @@ where let stderr_file = std::fs::File::create(&stderr_path) .map_err(|err| format!("Git-Fehlerdatei konnte nicht erstellt werden: {err}"))?; - let mut child = Command::new("git") + let mut child = git_command() .arg("-C") .arg(repo) .args(args) @@ -2218,7 +2231,7 @@ where I: IntoIterator, S: AsRef, { - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(path) .args(args) @@ -2442,7 +2455,7 @@ mod tests { I: IntoIterator, S: AsRef, { - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(repo) .args(args) @@ -2463,7 +2476,7 @@ mod tests { I: IntoIterator, S: AsRef, { - let output = Command::new("git") + let output = git_command() .arg("-C") .arg(repo) .args(args) @@ -2971,7 +2984,7 @@ mod tests { run_git_test(&repo.path, ["commit", "-q", "-am", "main change"]); // The merge is expected to fail with a conflict, so run git directly. - let _ = Command::new("git") + let _ = git_command() .arg("-C") .arg(&repo.path) .args(["merge", "--no-edit", "feature"]) @@ -3024,7 +3037,7 @@ mod tests { fs::write(repo.path.join("file.txt"), "ours change\n").expect("main change"); run_git_test(&repo.path, ["commit", "-q", "-am", "main change"]); - let _ = Command::new("git") + let _ = git_command() .arg("-C") .arg(&repo.path) .args(["merge", "--no-edit", "feature"]) @@ -3065,7 +3078,7 @@ mod tests { fs::write(repo.path.join("img.bin"), [0u8, 7, 7]).expect("main binary"); run_git_test(&repo.path, ["commit", "-q", "-am", "main bin"]); - let _ = Command::new("git") + let _ = git_command() .arg("-C") .arg(&repo.path) .args(["merge", "--no-edit", "feature"])