11use gix_credentials:: { helper, program:: Kind , Program } ;
22
3- #[ cfg( windows) ]
4- const GIT : & str = "git.exe" ;
5- #[ cfg( not( windows) ) ]
6- const GIT : & str = "git" ;
3+ static GIT : once_cell:: sync:: Lazy < & ' static str > =
4+ once_cell:: sync:: Lazy :: new ( || gix_path:: env:: exe_invocation ( ) . to_str ( ) . expect ( "not illformed" ) ) ;
75
86#[ cfg( windows) ]
97const SH : & str = "sh" ;
@@ -13,10 +11,11 @@ const SH: &str = "/bin/sh";
1311#[ test]
1412fn empty ( ) {
1513 let prog = Program :: from_custom_definition ( "" ) ;
14+ let git = * GIT ;
1615 assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args } if name_and_args == "" ) ) ;
1716 assert_eq ! (
1817 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
19- format!( r#""{GIT }" "credential-" "store""# ) ,
18+ format!( r#""{git }" "credential-" "store""# ) ,
2019 "not useful, but allowed, would have to be caught elsewhere"
2120 ) ;
2221}
@@ -36,32 +35,35 @@ fn simple_script_in_path() {
3635fn name_with_args ( ) {
3736 let input = "name --arg --bar=\" a b\" " ;
3837 let prog = Program :: from_custom_definition ( input) ;
38+ let git = * GIT ;
3939 assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
4040 assert_eq ! (
4141 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
42- format!( r#""{GIT }" "credential-name" "--arg" "--bar=a b" "store""# )
42+ format!( r#""{git }" "credential-name" "--arg" "--bar=a b" "store""# )
4343 ) ;
4444}
4545
4646#[ test]
4747fn name_with_special_args ( ) {
4848 let input = "name --arg --bar=~/folder/in/home" ;
4949 let prog = Program :: from_custom_definition ( input) ;
50+ let git = * GIT ;
5051 assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
5152 assert_eq ! (
5253 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
53- format!( r#""{SH}" "-c" "{GIT } credential-name --arg --bar=~/folder/in/home \"$@\"" "--" "store""# )
54+ format!( r#""{SH}" "-c" "{git } credential-name --arg --bar=~/folder/in/home \"$@\"" "--" "store""# )
5455 ) ;
5556}
5657
5758#[ test]
5859fn name ( ) {
5960 let input = "name" ;
6061 let prog = Program :: from_custom_definition ( input) ;
62+ let git = * GIT ;
6163 assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
6264 assert_eq ! (
6365 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
64- format!( r#""{GIT }" "credential-name" "store""# ) ,
66+ format!( r#""{git }" "credential-name" "store""# ) ,
6567 "we detect that this can run without shell, which is also more portable on windows"
6668 ) ;
6769}
0 commit comments