@@ -15,7 +15,7 @@ use gix::objs::WriteTo;
15
15
use gix:: status:: index_worktree;
16
16
use std:: borrow:: Cow ;
17
17
use std:: collections:: HashSet ;
18
- use std:: ffi:: OsStr ;
18
+ use std:: ffi:: OsString ;
19
19
#[ cfg( unix) ]
20
20
use std:: os:: unix:: fs:: PermissionsExt ;
21
21
#[ cfg( windows) ]
@@ -417,17 +417,15 @@ impl RepositoryExt for git2::Repository {
417
417
signature_storage. write_all ( buffer) ?;
418
418
let buffer_file_to_sign_path = signature_storage. into_temp_path ( ) ;
419
419
420
- let gpg_program = config. trusted_program ( "gpg.ssh.program" ) ;
421
- let mut gpg_program = gpg_program. unwrap_or ( Cow :: Borrowed ( OsStr :: new ( "ssh-keygen" ) ) ) ;
422
- // if cmd is "", use gpg
423
- if gpg_program. is_empty ( ) {
424
- gpg_program = Cow :: Borrowed ( OsStr :: new ( "ssh-keygen" ) ) ;
425
- }
420
+ let gpg_program = config
421
+ . trusted_program ( "gpg.ssh.program" )
422
+ . filter ( |program| !program. is_empty ( ) )
423
+ . map_or_else (
424
+ || Path :: new ( "ssh-keygen" ) . into ( ) ,
425
+ |program| Cow :: Owned ( program. into_owned ( ) . into ( ) ) ,
426
+ ) ;
426
427
427
- let mut cmd_string = format ! (
428
- "{} -Y sign -n git -f " ,
429
- gix:: path:: os_str_into_bstr( gpg_program. as_ref( ) ) ?
430
- ) ;
428
+ let mut cmd_string = format ! ( "{} -Y sign -n git -f " , gpg_program. display( ) ) ;
431
429
432
430
let buffer_file_to_sign_path_str = buffer_file_to_sign_path
433
431
. to_str ( )
@@ -453,16 +451,14 @@ impl RepositoryExt for git2::Repository {
453
451
let args = format ! (
454
452
"{} -U {}" ,
455
453
key_file_path. to_string_lossy( ) ,
456
- buffer_file_to_sign_path . to_string_lossy ( )
454
+ buffer_file_to_sign_path_str ,
457
455
) ;
458
456
cmd_string += & args;
459
457
} else {
460
458
let args = format ! ( "{} {}" , signing_key, buffer_file_to_sign_path_str) ;
461
459
cmd_string += & args;
462
460
} ;
463
- let mut signing_cmd: std:: process:: Command = gix:: command:: prepare ( cmd_string)
464
- . with_shell_disallow_manual_argument_splitting ( )
465
- . into ( ) ;
461
+ let mut signing_cmd: std:: process:: Command = command_with_login_shell ( cmd_string) ;
466
462
let output = signing_cmd
467
463
. stderr ( Stdio :: piped ( ) )
468
464
. stdout ( Stdio :: piped ( ) )
@@ -484,20 +480,21 @@ impl RepositoryExt for git2::Repository {
484
480
} else {
485
481
let gpg_program = config
486
482
. trusted_program ( "gpg.program" )
487
- . map ( |program| Cow :: Owned ( program. into_owned ( ) . into ( ) ) )
488
- . unwrap_or_else ( || Path :: new ( "gpg" ) . into ( ) ) ;
483
+ . filter ( |program| !program. is_empty ( ) )
484
+ . map_or_else (
485
+ || Path :: new ( "gpg" ) . into ( ) ,
486
+ |program| Cow :: Owned ( program. into_owned ( ) . into ( ) ) ,
487
+ ) ;
489
488
490
- let mut cmd = std:: process:: Command :: new ( gpg_program. as_ref ( ) ) ;
489
+ let mut cmd = command_with_login_shell ( format ! (
490
+ "{gpg_program} --status-fd=2 -bsau {signing_key} -" ,
491
+ gpg_program = gpg_program. display( ) ,
492
+ ) ) ;
491
493
492
- cmd. args ( [ "--status-fd=2" , "-bsau" , signing_key] )
493
- . arg ( "-" )
494
- . stdout ( Stdio :: piped ( ) )
494
+ cmd. stdout ( Stdio :: piped ( ) )
495
495
. stderr ( Stdio :: piped ( ) )
496
496
. stdin ( Stdio :: piped ( ) ) ;
497
497
498
- #[ cfg( windows) ]
499
- cmd. creation_flags ( 0x08000000 ) ; // CREATE_NO_WINDOW
500
-
501
498
let mut child = match cmd. spawn ( ) {
502
499
Ok ( child) => child,
503
500
Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
@@ -582,6 +579,13 @@ impl RepositoryExt for git2::Repository {
582
579
}
583
580
}
584
581
582
+ pub fn command_with_login_shell ( shell_cmd : impl Into < OsString > ) -> std:: process:: Command {
583
+ gix:: command:: prepare ( shell_cmd)
584
+ . with_shell_disallow_manual_argument_splitting ( )
585
+ . with_shell_program ( gix:: path:: env:: login_shell ( ) . unwrap_or ( "bash" . as_ref ( ) ) )
586
+ . into ( )
587
+ }
588
+
585
589
/// Signs the buffer with the configured gpg key, returning the signature.
586
590
pub fn is_literal_ssh_key ( string : & str ) -> ( bool , & str ) {
587
591
if let Some ( key) = string. strip_prefix ( "key::" ) {
0 commit comments