Skip to content

Commit 1c1cfa4

Browse files
committed
fix: Set CREATE_NO_WINDOW flag when executing Git hooks
1 parent 6b588b4 commit 1c1cfa4

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

git2-hooks/src/hookspath.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use git2::Repository;
33
use crate::{error::Result, HookResult, HooksError};
44

55
use std::{
6-
env, path::Path, path::PathBuf, process::Command, str::FromStr,
6+
env,
7+
path::{Path, PathBuf},
8+
process::Command,
9+
str::FromStr,
710
};
811

912
pub struct HookPaths {
@@ -118,6 +121,7 @@ impl HookPaths {
118121
.unwrap_or_else(|| "bash".into());
119122
let output = Command::new(git_shell)
120123
.args(bash_args)
124+
.with_no_window()
121125
.current_dir(&self.pwd)
122126
// This call forces Command to handle the Path environment correctly on windows,
123127
// the specific env set here does not matter
@@ -197,3 +201,20 @@ fn find_bash_executable() -> Option<PathBuf> {
197201
fn find_default_unix_shell() -> Option<PathBuf> {
198202
env::var_os("SHELL").map(PathBuf::from)
199203
}
204+
205+
trait CommandExt {
206+
fn with_no_window(&mut self) -> &mut Self;
207+
}
208+
209+
impl CommandExt for Command {
210+
/// On Windows, CLI applications that aren't the window's subsystem will
211+
/// create and show a console window that pops up next to the main
212+
/// application window when run. We disable this behavior by setting the
213+
/// `CREATE_NO_WINDOW` flag.
214+
#[inline]
215+
fn with_no_window(&mut self) -> &mut Self {
216+
use std::os::windows::process::CommandExt;
217+
#[cfg(windows)]
218+
self.creation_flags(0x0800_0000)
219+
}
220+
}

0 commit comments

Comments
 (0)