1
1
use gix_credentials:: { helper, program:: Kind , Program } ;
2
2
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" ) ) ;
7
5
8
6
#[ cfg( windows) ]
9
7
const SH : & str = "sh" ;
@@ -13,10 +11,11 @@ const SH: &str = "/bin/sh";
13
11
#[ test]
14
12
fn empty ( ) {
15
13
let prog = Program :: from_custom_definition ( "" ) ;
14
+ let git = * GIT ;
16
15
assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args } if name_and_args == "" ) ) ;
17
16
assert_eq ! (
18
17
format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
19
- format!( r#""{GIT }" "credential-" "store""# ) ,
18
+ format!( r#""{git }" "credential-" "store""# ) ,
20
19
"not useful, but allowed, would have to be caught elsewhere"
21
20
) ;
22
21
}
@@ -36,32 +35,35 @@ fn simple_script_in_path() {
36
35
fn name_with_args ( ) {
37
36
let input = "name --arg --bar=\" a b\" " ;
38
37
let prog = Program :: from_custom_definition ( input) ;
38
+ let git = * GIT ;
39
39
assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
40
40
assert_eq ! (
41
41
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""# )
43
43
) ;
44
44
}
45
45
46
46
#[ test]
47
47
fn name_with_special_args ( ) {
48
48
let input = "name --arg --bar=~/folder/in/home" ;
49
49
let prog = Program :: from_custom_definition ( input) ;
50
+ let git = * GIT ;
50
51
assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
51
52
assert_eq ! (
52
53
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""# )
54
55
) ;
55
56
}
56
57
57
58
#[ test]
58
59
fn name ( ) {
59
60
let input = "name" ;
60
61
let prog = Program :: from_custom_definition ( input) ;
62
+ let git = * GIT ;
61
63
assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
62
64
assert_eq ! (
63
65
format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
64
- format!( r#""{GIT }" "credential-name" "store""# ) ,
66
+ format!( r#""{git }" "credential-name" "store""# ) ,
65
67
"we detect that this can run without shell, which is also more portable on windows"
66
68
) ;
67
69
}
0 commit comments