1
1
use crate :: SyncContext ;
2
2
use crate :: josh:: JoshProxy ;
3
- use crate :: utils:: { check_output , check_output_at , ensure_clean_git_state } ;
3
+ use crate :: utils:: { StderrMode , ensure_clean_git_state , run_command , run_command_at } ;
4
4
use anyhow:: { Context , Error } ;
5
5
use std:: path:: { Path , PathBuf } ;
6
6
@@ -36,7 +36,7 @@ impl GitSync {
36
36
pub fn rustc_pull ( & self ) -> Result < PullResult , RustcPullError > {
37
37
// The upstream commit that we want to pull
38
38
let upstream_sha = {
39
- let out = check_output ( [
39
+ let out = run_command ( [
40
40
"git" ,
41
41
"ls-remote" ,
42
42
& format ! ( "https://github.com/{UPSTREAM_REPO}" ) ,
@@ -62,7 +62,7 @@ impl GitSync {
62
62
& self . context . config . construct_josh_filter ( ) ,
63
63
) ;
64
64
65
- let orig_head = check_output ( [ "git" , "rev-parse" , "HEAD" ] ) ?;
65
+ let orig_head = run_command ( [ "git" , "rev-parse" , "HEAD" ] ) ?;
66
66
println ! (
67
67
"previous upstream base: {:?}" ,
68
68
self . context. last_upstream_sha
@@ -101,8 +101,8 @@ To prepare for merging from {UPSTREAM_REPO}."#,
101
101
. last_upstream_sha_path
102
102
. to_string_lossy ( )
103
103
. to_string ( ) ;
104
- check_output ( & [ "git" , "add" , & config_path] ) ?;
105
- check_output ( & [
104
+ run_command ( & [ "git" , "add" , & config_path] ) ?;
105
+ run_command ( & [
106
106
"git" ,
107
107
"commit" ,
108
108
& config_path,
@@ -116,24 +116,23 @@ To prepare for merging from {UPSTREAM_REPO}."#,
116
116
let mut git_reset = GitResetOnDrop :: new ( orig_head) ;
117
117
118
118
// Fetch given rustc commit.
119
- check_output ( & [ "git" , "fetch" , & josh_url] )
120
- . context ( "cannot fetch git state through Josh" ) ?;
119
+ run_command ( & [ "git" , "fetch" , & josh_url] ) . context ( "cannot fetch git state through Josh" ) ?;
121
120
122
121
// This should not add any new root commits. So count those before and after merging.
123
122
let num_roots = || -> anyhow:: Result < u32 > {
124
123
Ok (
125
- check_output ( & [ "git" , "rev-list" , "HEAD" , "--max-parents=0" , "--count" ] )
124
+ run_command ( & [ "git" , "rev-list" , "HEAD" , "--max-parents=0" , "--count" ] )
126
125
. context ( "failed to determine the number of root commits" ) ?
127
126
. parse :: < u32 > ( ) ?,
128
127
)
129
128
} ;
130
129
let num_roots_before = num_roots ( ) ?;
131
130
132
131
let sha =
133
- check_output ( & [ "git" , "rev-parse" , "HEAD" ] ) . context ( "failed to get current commit" ) ?;
132
+ run_command ( & [ "git" , "rev-parse" , "HEAD" ] ) . context ( "failed to get current commit" ) ?;
134
133
135
134
// The filtered SHA of upstream
136
- let incoming_ref = check_output ( [ "git" , "rev-parse" , "FETCH_HEAD" ] ) ?;
135
+ let incoming_ref = run_command ( [ "git" , "rev-parse" , "FETCH_HEAD" ] ) ?;
137
136
println ! ( "incoming ref: {incoming_ref}" ) ;
138
137
139
138
let merge_message = format ! (
@@ -149,7 +148,7 @@ Filtered ref: {incoming_ref}
149
148
) ;
150
149
151
150
// Merge the fetched commit.
152
- check_output ( & [
151
+ run_command ( & [
153
152
"git" ,
154
153
"merge" ,
155
154
"FETCH_HEAD" ,
@@ -161,7 +160,7 @@ Filtered ref: {incoming_ref}
161
160
. context ( "FAILED to merge new commits, something went wrong" ) ?;
162
161
163
162
let current_sha =
164
- check_output ( & [ "git" , "rev-parse" , "HEAD" ] ) . context ( "FAILED to get current commit" ) ?;
163
+ run_command ( & [ "git" , "rev-parse" , "HEAD" ] ) . context ( "FAILED to get current commit" ) ?;
165
164
if current_sha == sha {
166
165
eprintln ! (
167
166
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
@@ -210,10 +209,10 @@ Filtered ref: {incoming_ref}
210
209
println ! ( "Preparing {user_upstream_url} (base: {base_upstream_sha})..." ) ;
211
210
212
211
// Check if the remote branch doesn't already exist
213
- if check_output_at (
212
+ if run_command_at (
214
213
& [ "git" , "fetch" , & user_upstream_url, branch] ,
215
214
& rustc_git,
216
- true ,
215
+ StderrMode :: Print ,
217
216
)
218
217
. is_ok ( )
219
218
{
@@ -223,45 +222,45 @@ Filtered ref: {incoming_ref}
223
222
}
224
223
225
224
// Download the base upstream SHA
226
- check_output_at (
225
+ run_command_at (
227
226
& [
228
227
"git" ,
229
228
"fetch" ,
230
229
& format ! ( "https://github.com/{UPSTREAM_REPO}" ) ,
231
230
& base_upstream_sha,
232
231
] ,
233
232
& rustc_git,
234
- false ,
233
+ StderrMode :: Print ,
235
234
)
236
235
. context ( "cannot download latest upstream SHA" ) ?;
237
236
238
237
// And push it to the user's fork's branch
239
- check_output_at (
238
+ run_command_at (
240
239
& [
241
240
"git" ,
242
241
"push" ,
243
242
& user_upstream_url,
244
243
& format ! ( "{base_upstream_sha}:refs/heads/{branch}" ) ,
245
244
] ,
246
245
& rustc_git,
247
- true ,
246
+ StderrMode :: Ignore ,
248
247
)
249
248
. context ( "cannot push to your fork" ) ?;
250
249
println ! ( ) ;
251
250
252
251
// Do the actual push from the subtree git repo
253
252
println ! ( "Pushing changes..." ) ;
254
- check_output ( & [ "git" , "push" , & josh_url, & format ! ( "HEAD:{branch}" ) ] ) ?;
253
+ run_command ( & [ "git" , "push" , & josh_url, & format ! ( "HEAD:{branch}" ) ] ) ?;
255
254
println ! ( ) ;
256
255
257
256
// Do a round-trip check to make sure the push worked as expected.
258
- check_output_at (
257
+ run_command_at (
259
258
& [ "git" , "fetch" , & josh_url, & branch] ,
260
259
& std:: env:: current_dir ( ) . unwrap ( ) ,
261
- true ,
260
+ StderrMode :: Ignore ,
262
261
) ?;
263
- let head = check_output ( & [ "git" , "rev-parse" , "HEAD" ] ) ?;
264
- let fetch_head = check_output ( & [ "git" , "rev-parse" , "FETCH_HEAD" ] ) ?;
262
+ let head = run_command ( & [ "git" , "rev-parse" , "HEAD" ] ) ?;
263
+ let fetch_head = run_command ( & [ "git" , "rev-parse" , "FETCH_HEAD" ] ) ?;
265
264
if head != fetch_head {
266
265
return Err ( anyhow:: anyhow!(
267
266
"Josh created a non-roundtrip push! Do NOT merge this into rustc!\n \
@@ -294,7 +293,7 @@ fn prepare_rustc_checkout() -> anyhow::Result<PathBuf> {
294
293
println ! (
295
294
"Cloning rustc into `{path}`. Use RUSTC_GIT environment variable to override the location of the checkout"
296
295
) ;
297
- check_output ( & [
296
+ run_command ( & [
298
297
"git" ,
299
298
"clone" ,
300
299
"--filter=blob:none" ,
@@ -329,7 +328,7 @@ impl Drop for GitResetOnDrop {
329
328
fn drop ( & mut self ) {
330
329
if !self . disarmed {
331
330
eprintln ! ( "Reverting HEAD to {}" , self . reset_to) ;
332
- check_output ( & [ "git" , "reset" , "--hard" , & self . reset_to ] )
331
+ run_command ( & [ "git" , "reset" , "--hard" , & self . reset_to ] )
333
332
. expect ( & format ! ( "cannot reset current branch to {}" , self . reset_to) ) ;
334
333
}
335
334
}
0 commit comments