mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
Set CREATE_NO_WINDOW flag when executing Git hooks (#2371)
This commit is contained in:
parent
2a590fd8cc
commit
d98171b2aa
2 changed files with 37 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))
|
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))
|
||||||
|
* Set `CREATE_NO_WINDOW` flag when executing Git hooks on Windows ([#2371](https://github.com/extrawurst/gitui/pull/2371))
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
* add popups for viewing, adding, updating and removing remotes [[@robin-thoene](https://github.com/robin-thoene)] ([#2172](https://github.com/extrawurst/gitui/issues/2172))
|
* add popups for viewing, adding, updating and removing remotes [[@robin-thoene](https://github.com/robin-thoene)] ([#2172](https://github.com/extrawurst/gitui/issues/2172))
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@ use git2::Repository;
|
||||||
use crate::{error::Result, HookResult, HooksError};
|
use crate::{error::Result, HookResult, HooksError};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env, path::Path, path::PathBuf, process::Command, str::FromStr,
|
env,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct HookPaths {
|
pub struct HookPaths {
|
||||||
|
|
@ -118,6 +121,7 @@ impl HookPaths {
|
||||||
.unwrap_or_else(|| "bash".into());
|
.unwrap_or_else(|| "bash".into());
|
||||||
let output = Command::new(git_shell)
|
let output = Command::new(git_shell)
|
||||||
.args(bash_args)
|
.args(bash_args)
|
||||||
|
.with_no_window()
|
||||||
.current_dir(&self.pwd)
|
.current_dir(&self.pwd)
|
||||||
// This call forces Command to handle the Path environment correctly on windows,
|
// This call forces Command to handle the Path environment correctly on windows,
|
||||||
// the specific env set here does not matter
|
// the specific env set here does not matter
|
||||||
|
|
@ -197,3 +201,34 @@ fn find_bash_executable() -> Option<PathBuf> {
|
||||||
fn find_default_unix_shell() -> Option<PathBuf> {
|
fn find_default_unix_shell() -> Option<PathBuf> {
|
||||||
env::var_os("SHELL").map(PathBuf::from)
|
env::var_os("SHELL").map(PathBuf::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait CommandExt {
|
||||||
|
/// The process is a console application that is being run without a
|
||||||
|
/// console window. Therefore, the console handle for the application is
|
||||||
|
/// not set.
|
||||||
|
///
|
||||||
|
/// This flag is ignored if the application is not a console application,
|
||||||
|
/// or if it used with either `CREATE_NEW_CONSOLE` or `DETACHED_PROCESS`.
|
||||||
|
///
|
||||||
|
/// See: <https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags>
|
||||||
|
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
||||||
|
|
||||||
|
fn with_no_window(&mut self) -> &mut Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommandExt for Command {
|
||||||
|
/// On Windows, CLI applications that aren't the window's subsystem will
|
||||||
|
/// create and show a console window that pops up next to the main
|
||||||
|
/// application window when run. We disable this behavior by setting the
|
||||||
|
/// `CREATE_NO_WINDOW` flag.
|
||||||
|
#[inline]
|
||||||
|
fn with_no_window(&mut self) -> &mut Self {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
self.creation_flags(Self::CREATE_NO_WINDOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue