1
+ use std:: env;
1
2
use std:: path:: { Path , PathBuf } ;
2
3
use std:: process:: { Command , Stdio } ;
3
4
@@ -108,23 +109,21 @@ fn exe_info() -> Option<BString> {
108
109
109
110
fn git_cmd ( executable : PathBuf ) -> Command {
110
111
let mut cmd = Command :: new ( executable) ;
111
-
112
- if cfg ! ( windows ) {
112
+ # [ cfg ( windows ) ]
113
+ {
113
114
use std:: os:: windows:: process:: CommandExt ;
114
115
const CREATE_NO_WINDOW : u32 = 0x08000000 ;
115
116
cmd. creation_flags ( CREATE_NO_WINDOW ) ;
116
-
117
- use std :: env ;
118
- let cwd = env:: var_os ( "SystemRoot" ) // Usually `C:\Windows`. Not to be confused with `C:\`.
117
+ }
118
+ let cwd = if cfg ! ( windows ) {
119
+ env:: var_os ( "SystemRoot" ) // Usually `C:\Windows`. Not to be confused with `C:\`.
119
120
. or_else ( || env:: var_os ( "windir" ) ) // Same. Less reliable, but some callers are unusual.
120
121
. map ( PathBuf :: from)
121
122
. filter ( |p| p. is_absolute ( ) )
122
- . unwrap_or_else ( env:: temp_dir) ;
123
- cmd. current_dir ( cwd) ;
123
+ . unwrap_or_else ( env:: temp_dir)
124
124
} else {
125
- cmd. current_dir ( "/" ) ;
126
- }
127
-
125
+ "/" . into ( )
126
+ } ;
128
127
// Git 2.8.0 and higher support --show-origin. The -l, -z, and --name-only options were
129
128
// supported even before that. In contrast, --show-scope was introduced later, in Git 2.26.0.
130
129
// Low versions of git are still sometimes used, and this is sometimes reasonable because
@@ -137,6 +136,7 @@ fn git_cmd(executable: PathBuf) -> Command {
137
136
// scope. Although GIT_CONFIG_NOSYSTEM will suppress this as well, passing --system omits it.
138
137
//
139
138
cmd. args ( [ "config" , "-lz" , "--show-origin" , "--name-only" ] )
139
+ . current_dir ( cwd)
140
140
. env ( "GIT_DIR" , NULL_DEVICE ) // Avoid getting local-scope config.
141
141
. env ( "GIT_WORK_TREE" , NULL_DEVICE ) // Just to avoid confusion when debugging.
142
142
. stdin ( Stdio :: null ( ) )
0 commit comments