1+ use std:: env;
12use std:: path:: { Path , PathBuf } ;
23use std:: process:: { Command , Stdio } ;
34
@@ -108,23 +109,21 @@ fn exe_info() -> Option<BString> {
108109
109110fn git_cmd ( executable : PathBuf ) -> Command {
110111 let mut cmd = Command :: new ( executable) ;
111-
112- if cfg ! ( windows ) {
112+ # [ cfg ( windows ) ]
113+ {
113114 use std:: os:: windows:: process:: CommandExt ;
114115 const CREATE_NO_WINDOW : u32 = 0x08000000 ;
115116 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:\`.
119120 . or_else ( || env:: var_os ( "windir" ) ) // Same. Less reliable, but some callers are unusual.
120121 . map ( PathBuf :: from)
121122 . filter ( |p| p. is_absolute ( ) )
122- . unwrap_or_else ( env:: temp_dir) ;
123- cmd. current_dir ( cwd) ;
123+ . unwrap_or_else ( env:: temp_dir)
124124 } else {
125- cmd. current_dir ( "/" ) ;
126- }
127-
125+ "/" . into ( )
126+ } ;
128127 // Git 2.8.0 and higher support --show-origin. The -l, -z, and --name-only options were
129128 // supported even before that. In contrast, --show-scope was introduced later, in Git 2.26.0.
130129 // Low versions of git are still sometimes used, and this is sometimes reasonable because
@@ -137,6 +136,7 @@ fn git_cmd(executable: PathBuf) -> Command {
137136 // scope. Although GIT_CONFIG_NOSYSTEM will suppress this as well, passing --system omits it.
138137 //
139138 cmd. args ( [ "config" , "-lz" , "--show-origin" , "--name-only" ] )
139+ . current_dir ( cwd)
140140 . env ( "GIT_DIR" , NULL_DEVICE ) // Avoid getting local-scope config.
141141 . env ( "GIT_WORK_TREE" , NULL_DEVICE ) // Just to avoid confusion when debugging.
142142 . stdin ( Stdio :: null ( ) )
0 commit comments