Skip to content

Commit d214105

Browse files
committed
suppress spawning processes in Windows
1 parent d9febce commit d214105

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/git/repository.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ use git2::{self, BranchType, Cred, Oid, RemoteCallbacks, Repository, Sort};
44
use std::collections::HashMap;
55
use std::path::{Path, PathBuf};
66
use std::process::Command;
7+
#[cfg(target_os = "windows")]
8+
use std::os::windows::process::CommandExt;
79

810
use crate::models::{BranchInfo, BranchMetadata, Commit, StashEntry};
911

1012
/// Run a git command in the specified directory and return stdout as a String.
1113
/// This is a standalone utility for handlers that don't need a full GitRepository.
1214
pub fn run_git(args: &[&str], repo_path: &Path) -> Result<String, String> {
13-
let output = Command::new("git")
14-
.args(args)
15-
.current_dir(repo_path)
16-
.output()
15+
let mut cmd = Command::new("git");
16+
cmd.args(args).current_dir(repo_path);
17+
18+
#[cfg(target_os = "windows")]
19+
{
20+
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
21+
}
22+
23+
let output = cmd.output()
1724
.map_err(|e| e.to_string())?;
1825

1926
if !output.status.success() {
@@ -180,10 +187,15 @@ impl GitRepository {
180187

181188
/// Run a git command in this repository and return stdout as a String.
182189
pub fn run_git(&self, args: &[&str]) -> Result<String> {
183-
let output = Command::new("git")
184-
.args(args)
185-
.current_dir(&self.path)
186-
.output()
190+
let mut cmd = Command::new("git");
191+
cmd.args(args).current_dir(&self.path);
192+
193+
#[cfg(target_os = "windows")]
194+
{
195+
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
196+
}
197+
198+
let output = cmd.output()
187199
.with_context(|| format!("Failed to run git with args {:?}", args))?;
188200

189201
if !output.status.success() {
@@ -196,10 +208,15 @@ impl GitRepository {
196208

197209
/// Run a git command in this repository and return stdout bytes.
198210
pub fn run_git_bytes(&self, args: &[&str]) -> Result<Vec<u8>> {
199-
let output = Command::new("git")
200-
.args(args)
201-
.current_dir(&self.path)
202-
.output()
211+
let mut cmd = Command::new("git");
212+
cmd.args(args).current_dir(&self.path);
213+
214+
#[cfg(target_os = "windows")]
215+
{
216+
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
217+
}
218+
219+
let output = cmd.output()
203220
.with_context(|| format!("Failed to run git with args {:?}", args))?;
204221

205222
if !output.status.success() {

src/handlers/explorer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use axum::{
55
};
66
use std::path::Path as StdPath;
77
use std::process::Command;
8+
#[cfg(target_os = "windows")]
9+
use std::os::windows::process::CommandExt;
810

911
use crate::config::Config;
1012
use crate::models::{ErrorResponse, SuccessResponse};
@@ -45,6 +47,7 @@ fn open_file(full_path: &StdPath) {
4547
let path_str = full_path.to_string_lossy().replace('/', "\\");
4648
let _ = Command::new("explorer")
4749
.args(&["/select,", &path_str])
50+
.creation_flags(0x08000000) // CREATE_NO_WINDOW
4851
.spawn();
4952
}
5053

@@ -70,11 +73,15 @@ fn open_directory(dir_path: &StdPath, full_path: &StdPath) {
7073
{
7174
let path_str = full_path.to_string_lossy().replace('/', "\\");
7275
let mut cmd = Command::new("explorer");
73-
cmd.args(&["/select,", &path_str]);
76+
cmd.args(&["/select,", &path_str])
77+
.creation_flags(0x08000000); // CREATE_NO_WINDOW
7478
if cmd.spawn().is_err() {
7579
// If file doesn't exist, just open the directory
7680
let dir_str = dir_path.to_string_lossy().replace('/', "\\");
77-
let _ = Command::new("explorer").arg(&dir_str).spawn();
81+
let _ = Command::new("explorer")
82+
.arg(&dir_str)
83+
.creation_flags(0x08000000) // CREATE_NO_WINDOW
84+
.spawn();
7885
}
7986
}
8087

0 commit comments

Comments
 (0)