Skip to content

Commit d98171b

Browse files
authored
Set CREATE_NO_WINDOW flag when executing Git hooks (#2371)
1 parent 2a590fd commit d98171b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixes
1414
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))
15+
* Set `CREATE_NO_WINDOW` flag when executing Git hooks on Windows ([#2371](https://github.com/extrawurst/gitui/pull/2371))
1516

1617
### Added
1718
* add popups for viewing, adding, updating and removing remotes [[@robin-thoene](https://github.com/robin-thoene)] ([#2172](https://github.com/extrawurst/gitui/issues/2172))

Diff for: git2-hooks/src/hookspath.rs

+36-1
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,34 @@ 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+
/// The process is a console application that is being run without a
207+
/// console window. Therefore, the console handle for the application is
208+
/// not set.
209+
///
210+
/// This flag is ignored if the application is not a console application,
211+
/// or if it used with either `CREATE_NEW_CONSOLE` or `DETACHED_PROCESS`.
212+
///
213+
/// See: <https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags>
214+
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
215+
216+
fn with_no_window(&mut self) -> &mut Self;
217+
}
218+
219+
impl CommandExt for Command {
220+
/// On Windows, CLI applications that aren't the window's subsystem will
221+
/// create and show a console window that pops up next to the main
222+
/// application window when run. We disable this behavior by setting the
223+
/// `CREATE_NO_WINDOW` flag.
224+
#[inline]
225+
fn with_no_window(&mut self) -> &mut Self {
226+
#[cfg(windows)]
227+
{
228+
use std::os::windows::process::CommandExt;
229+
self.creation_flags(Self::CREATE_NO_WINDOW);
230+
}
231+
232+
self
233+
}
234+
}

0 commit comments

Comments
 (0)