@@ -118,7 +118,7 @@ To prepare for merging from {UPSTREAM_REPO}."#,
118
118
. context ( "cannot create preparation commit" ) ?;
119
119
120
120
// Make sure that we reset the above commit if something fails
121
- let mut git_reset = GitResetOnDrop :: default ( ) ;
121
+ let mut git_reset = GitResetOnDrop :: new ( orig_head ) ;
122
122
123
123
// Fetch given rustc commit.
124
124
check_output ( & [ "git" , "fetch" , & josh_url] )
@@ -311,13 +311,20 @@ fn prepare_rustc_checkout() -> anyhow::Result<PathBuf> {
311
311
Ok ( PathBuf :: from ( path) )
312
312
}
313
313
314
- /// Removes the last commit on drop, unless `disarm` is called first.
315
- #[ derive( Default ) ]
314
+ /// Restores HEAD to `reset_to` on drop, unless `disarm` is called first.
316
315
struct GitResetOnDrop {
317
316
disarmed : bool ,
317
+ reset_to : String ,
318
318
}
319
319
320
320
impl GitResetOnDrop {
321
+ fn new ( current_sha : String ) -> Self {
322
+ Self {
323
+ disarmed : false ,
324
+ reset_to : current_sha,
325
+ }
326
+ }
327
+
321
328
fn disarm ( & mut self ) {
322
329
self . disarmed = true ;
323
330
}
@@ -326,9 +333,9 @@ impl GitResetOnDrop {
326
333
impl Drop for GitResetOnDrop {
327
334
fn drop ( & mut self ) {
328
335
if !self . disarmed {
329
- eprintln ! ( "Reverting last commit" ) ;
330
- check_output ( & [ "git" , "reset" , "--hard" , "HEAD^" ] )
331
- . expect ( "cannot reset last git commit" ) ;
336
+ eprintln ! ( "Reverting HEAD to {}" , self . reset_to ) ;
337
+ check_output ( & [ "git" , "reset" , "--hard" , & self . reset_to ] )
338
+ . expect ( & format ! ( "cannot reset current branch to {}" , self . reset_to ) ) ;
332
339
}
333
340
}
334
341
}
0 commit comments