@@ -8,7 +8,7 @@ use crate::build_system::rustc_info::get_default_sysroot;
8
8
use super :: build_sysroot:: { BUILD_SYSROOT , ORIG_BUILD_SYSROOT , SYSROOT_RUSTC_VERSION , SYSROOT_SRC } ;
9
9
use super :: path:: { Dirs , RelPath } ;
10
10
use super :: rustc_info:: get_rustc_version;
11
- use super :: utils:: { copy_dir_recursively, retry_spawn_and_wait, spawn_and_wait} ;
11
+ use super :: utils:: { copy_dir_recursively, git_command , retry_spawn_and_wait, spawn_and_wait} ;
12
12
13
13
pub ( crate ) fn prepare ( dirs : & Dirs ) {
14
14
if RelPath :: DOWNLOAD . to_path ( dirs) . exists ( ) {
@@ -96,14 +96,14 @@ impl GitRepo {
96
96
fn clone_repo ( download_dir : & Path , repo : & str , rev : & str ) {
97
97
eprintln ! ( "[CLONE] {}" , repo) ;
98
98
// Ignore exit code as the repo may already have been checked out
99
- Command :: new ( "git" ) . arg ( " clone") . arg ( repo) . arg ( & download_dir) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
99
+ git_command ( None , " clone") . arg ( repo) . arg ( download_dir) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
100
100
101
- let mut clean_cmd = Command :: new ( "git ") ;
102
- clean_cmd. arg ( "checkout" ) . arg ( " --") . arg ( "." ) . current_dir ( & download_dir ) ;
101
+ let mut clean_cmd = git_command ( download_dir , "checkout ") ;
102
+ clean_cmd. arg ( "--" ) . arg ( "." ) ;
103
103
spawn_and_wait ( clean_cmd) ;
104
104
105
- let mut checkout_cmd = Command :: new ( "git ") ;
106
- checkout_cmd. arg ( "checkout" ) . arg ( " -q") . arg ( rev) . current_dir ( download_dir ) ;
105
+ let mut checkout_cmd = git_command ( download_dir , "checkout ") ;
106
+ checkout_cmd. arg ( "-q" ) . arg ( rev) ;
107
107
spawn_and_wait ( checkout_cmd) ;
108
108
}
109
109
@@ -159,25 +159,16 @@ fn clone_repo_shallow_github(dirs: &Dirs, download_dir: &Path, user: &str, repo:
159
159
}
160
160
161
161
fn init_git_repo ( repo_dir : & Path ) {
162
- let mut git_init_cmd = Command :: new ( "git ") ;
163
- git_init_cmd. arg ( "init" ) . arg ( " -q") . current_dir ( repo_dir ) ;
162
+ let mut git_init_cmd = git_command ( repo_dir , "init ") ;
163
+ git_init_cmd. arg ( "-q" ) ;
164
164
spawn_and_wait ( git_init_cmd) ;
165
165
166
- let mut git_add_cmd = Command :: new ( "git ") ;
167
- git_add_cmd. arg ( "add" ) . arg ( "." ) . current_dir ( repo_dir ) ;
166
+ let mut git_add_cmd = git_command ( repo_dir , "add ") ;
167
+ git_add_cmd. arg ( "." ) ;
168
168
spawn_and_wait ( git_add_cmd) ;
169
169
170
- let mut git_commit_cmd = Command :: new ( "git" ) ;
171
- git_commit_cmd
172
- . arg ( "-c" )
173
- . arg ( "user.name=Dummy" )
174
- . arg ( "-c" )
175
- . arg ( "user.email=dummy@example.com" )
176
- . arg ( "commit" )
177
- . arg ( "-m" )
178
- . arg ( "Initial commit" )
179
- . arg ( "-q" )
180
- . current_dir ( repo_dir) ;
170
+ let mut git_commit_cmd = git_command ( repo_dir, "commit" ) ;
171
+ git_commit_cmd. arg ( "-m" ) . arg ( "Initial commit" ) . arg ( "-q" ) ;
181
172
spawn_and_wait ( git_commit_cmd) ;
182
173
}
183
174
@@ -212,16 +203,8 @@ fn apply_patches(dirs: &Dirs, crate_name: &str, target_dir: &Path) {
212
203
target_dir. file_name( ) . unwrap( ) ,
213
204
patch. file_name( ) . unwrap( )
214
205
) ;
215
- let mut apply_patch_cmd = Command :: new ( "git" ) ;
216
- apply_patch_cmd
217
- . arg ( "-c" )
218
- . arg ( "user.name=Dummy" )
219
- . arg ( "-c" )
220
- . arg ( "user.email=dummy@example.com" )
221
- . arg ( "am" )
222
- . arg ( patch)
223
- . arg ( "-q" )
224
- . current_dir ( target_dir) ;
206
+ let mut apply_patch_cmd = git_command ( target_dir, "am" ) ;
207
+ apply_patch_cmd. arg ( patch) . arg ( "-q" ) ;
225
208
spawn_and_wait ( apply_patch_cmd) ;
226
209
}
227
210
}
0 commit comments