@@ -3,7 +3,10 @@ use git2::Repository;
3
3
use crate :: { error:: Result , HookResult , HooksError } ;
4
4
5
5
use std:: {
6
- env, path:: Path , path:: PathBuf , process:: Command , str:: FromStr ,
6
+ env,
7
+ path:: { Path , PathBuf } ,
8
+ process:: Command ,
9
+ str:: FromStr ,
7
10
} ;
8
11
9
12
pub struct HookPaths {
@@ -118,6 +121,7 @@ impl HookPaths {
118
121
. unwrap_or_else ( || "bash" . into ( ) ) ;
119
122
let output = Command :: new ( git_shell)
120
123
. args ( bash_args)
124
+ . with_no_window ( )
121
125
. current_dir ( & self . pwd )
122
126
// This call forces Command to handle the Path environment correctly on windows,
123
127
// the specific env set here does not matter
@@ -197,3 +201,34 @@ fn find_bash_executable() -> Option<PathBuf> {
197
201
fn find_default_unix_shell ( ) -> Option < PathBuf > {
198
202
env:: var_os ( "SHELL" ) . map ( PathBuf :: from)
199
203
}
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